Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# doesn't throw NullReferenceException at developer machine

I have a code which looks like this:

public partical class frmXXX : Form
{

  SomeObject foo = null;

  public void XYZ()
  {
    foo.ABC.DEF(foo.XXX, foo.YYY, foo.ZZZ);
    somethingElse();
  }

  ...

}

It appears that I had a bug where I called XYZ() when foo is null. The program crashed with a NullReferenceException at the customer, which is what I would expect. However, on my development machine I do not get an Exception. I also verified with the debugger that foo is actually null. The debugger says that it is null.

Once the null object was invoked, the method will end, so somethingElse(); is not called. It is like a silent exception. Is there a chance that my development machine is wrongly configured, or do I enable something?

like image 619
Daniel Marschall Avatar asked Feb 05 '26 17:02

Daniel Marschall


1 Answers

Cntrl + Alt + E (Or Debug -> Exceptions or in VS2017 Debug -> Windows -> Exception Settings) Select Reset All, this will return the default exceptions.

Also make sure Just My Code is checked. You can find this under Debug -> Options. This will bring you to the Debugger -> General options. Here you can check Just My Code.

like image 105
Jurjen Avatar answered Feb 07 '26 07:02

Jurjen