ScruffyDuck
ScruffyDuck

Reputation: 2666

Null Reference Exception not related to a Null Object

I am confused ( that is easy enough!). I have a small snippet of code that I have taken a screenshot of.

The NRE arises after a failed test for a file path. Nothing there is null. The SceneryAreas object is initialized just before this test. However (and my screenshot did not pick it up) it seems that in the line SceneryAreas.Clear(); that SceneryAreas is null. Is it possible that the error is being shown on the wrong line and more to the point how could the instantiated object become null at this point?

Screenshot of VS 2010 IDE

Many thanks for any suggestions - I have never seen this before.

Upvotes: 3

Views: 926

Answers (3)

Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

As others said, the file does not correspond with the one used to build the assembly. The easiest way to check this is trying to set a breakpoint on the file, you will see a red circle saying that the file is different from the built one.

Upvotes: 1

Olly
Olly

Reputation: 6026

It is possible that the error's shown against the wrong line. Try rebuilding your project to make sure that the source files are in sync with the code being debugged. Also, check the stack trace under View Detail... to see exactly where the exception is being thrown.

Upvotes: 1

Noel Kennedy
Noel Kennedy

Reputation: 12258

Your source code or symbols file is not in synch with your compiled code, hence the debugger is highlighting the wrong line.

If you recompile and re-run it should break on the line in your source which is causing the problem.

Upvotes: 5

Related Questions