Catch Exception in Application Startup (VS.Net)
I'm getting a System.NullReferenceException when my application starts up (after a small login screen) which doesn't crash the entire app but prevents it from loading correctly.
How can I get the VS.Net debugge开发者_运维技巧r to stop at the error so I can fix it?
The output I'm getting in the Immediate Window is:
A first chance exception of type 'System.NullReferenceException' occurred in GrelisCrampApp.exe
Go to Debug > Exceptions and turn on Thrown for Common Language Runtime Exception. That will cause VS to break when the exception is thrown instead of when it is unhandled.
At what point does this occur?
It is likely an issue in your destructor for the login form, or something that happens after this.
I suggest adding try catch blocks around code in that area of the program and seeing if you can catch where it is going wrong. This should help you narrow down the issue easily
Try the following once:-
Navigate to "Debug/Exceptions"
Expand the "Common Language Runtime Exceptions" tree.
Expand the "System" branch.
Scroll down to where "NullReferenceException" is, and check the "throw" checkbox, and uncheck the "user-handled".
精彩评论