This it what happen when you try to use a reference that is not set to a valid instance of an object - ie. a null reference.
The following may be helpful when you wish to track down null references, and other exceptions, when running a program under a debugger. It's particularly useful when you are working with code written by others, and trying to figure things out :)
AppDomain has two interesting events:
AppDomain.FirstChanceException Event[
^]
and
AppDomain.UnhandledException Event[
^]
So you can write
static void FirstChanceHandler(object source, FirstChanceExceptionEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
#endif
}
And then assign the handler in your Main method
static void Main()
{
AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;
}
Regards
Espen Harlinn