Tuesday, June 19, 2012

A first chance exception of type 'System.NullReferenceException'

While debugging an ASP.NET application, I kept encountering errors similar to the following:

A first chance exception of type 'System.NullReferenceException' occurred in MyApp.dll
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll

At first I was simply ignoring the error since my application appears to be working, and except for the assembly DLL name, it doesn't tell me which source file or line number the error is occurring in. Then I happen to find this nice little feature to help me. Go to the Debug menu -> Exceptions -> then drill down to Common Language Runtime Exceptions -> System and look for the specific exception that you're having problems with.




Check the Thrown checkbox, uncheck the User-unhandled checkbox and rerun. Visual Studio will now break at the point where the exception occurs.

No comments:

Post a Comment