Finding the source of the NullReferenceException in the ShowDialog () method

It's in WPF (C #).

I am trying to find which object is throwing a NullReferenceException when I call the ShowDialog () method on a Window object. The code is similar to this:

MyWindow myWindow = new MyWindow();
//Some properties of myWindows are set here
try
{
    myWindow.ShowDialog();
}
catch (Exception) //In here I catch a NullReferenceException
{

}

      

Is there a way to find the reason for the exception? I put a breakpoint at the very beginning of the Window_Loaded event handler in the MyWindow class, but it just doesn't fire.

+3


source to share


1 answer


Go to Debug> Exceptions and check the Thrown checkbox for common language runtime exceptions (or more specifically, if you prefer, a NullReferenceException is deeper in the tree structure)



Then run and the debugger will catch the exception on the line it was posted on.

+11


source







All Articles