Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I allow breaking on 'System.NullReferenceException' in VS2010?

I have a VS 2010 C# .NET 4 project. The issue is that the program is not breaking on 'NullReferenceException' errors during debugging.

The output window will display the following:

A first chance exception of type 'System.NullReferenceException' occurred in myProgram.exe

...but the debugger will just exit out of the function and continue running the rest of the program.

How do I change this behavior so that the debugger will break on these exceptions?

like image 742
Mike Webb Avatar asked Dec 17 '10 22:12

Mike Webb


People also ask

What does system NullReferenceException mean?

A NullReferenceException exception is thrown when you try to access a member on a type whose value is null . A NullReferenceException exception typically reflects developer error and is thrown in the following scenarios: You've forgotten to instantiate a reference type.

How do I catch system NullReferenceException?

Handling the error Being a plain old C# exception, NullReferenceException can be caught using a try/catch : try { string s = null; s. ToString(); } catch (NullReferenceException e) { // Do something with e, please. }

Why am I getting a NullReferenceException?

The runtime throwing a NullReferenceException always means the same thing: you are trying to use a reference, and the reference is not initialized (or it was once initialized, but is no longer initialized). This means the reference is null , and you cannot access members (such as methods) through a null reference.


1 Answers

Go to Debug -> Exceptions -> Search for NullReferenceException and check the "thrown" checkbox.

like image 60
Femaref Avatar answered Sep 28 '22 09:09

Femaref