Object reference not set to an instance of an object.

How to troubleshoot Object reference not set to an instance of an object in C#.

Put a break point in the code, execute the code
Inspect the value where you are getting this error

Inspect the value you are assigning to a variable/object or inspect the object itself that is being assigned the value

open the watch1 widow (Dubug>Windows>Watch>Watch1), type in the variable exactly as it appears in code with the dot.  Are you getting a value for the field?
Are you getting nullreference exception instead? If so there is where the exception is coming from.

It is possible that are you fetching the value from the wrong place or you are assigning a value to something that does not exists.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*