ellic
ellic

Reputation: 798

What's the cause of this exception in Windows Phone

It's a little strange that my Windows Phone App will exit without any Warning by chance, most of the time it works fine.

Then I trace the Application_UnhandledException, find that the Exception message is:

[ExceptionMessage]:[NullReferenceException]
[StackTrace]:[
   at wpapp.MainPage.<DispatcherLoad>b__1(Object sender, EventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
]

There is no detailed information for me to find out the cause of the exception. Has anybody met this exception before and got a solution for it?

Any suggestions will be appreciated.

Upvotes: 1

Views: 63

Answers (1)

Kevin Gosse
Kevin Gosse

Reputation: 39007

From the look of it, it's likely that you have a DispatcherLoad method in your MainPage, and you're calling a lambda function in that method. Something like:

    private void DispatcherLoad()
    {
        this.Dispatcher.BeginInvoke(() => Console.WriteLine("hello world;"));
    }

The error is occuring in the lambda (in my sample: the Console.WriteLine("hello world;") part). So now you just have to find the right lambda, and find out why your code crashes.

Given the "object sender, EventArgs e" parameters, it's probably an event handler. Are you assigning a lambda to an event handler somewhere in the DispatcherLoad function? For instance:

    private void DispatcherLoad()
    {
        this.Button.Click += (sender, e) => Console.WriteLine("hello world;");
    }

Note: if there's many lambdas in your method and you can't figure which one is crashing, you can try opening your assembly with Reflector (http://www.reflector.net/). It will decompile your dll, and you can then see which lambda is called "<DispatcherLoad>b__1".

Upvotes: 2

Related Questions