Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Visual Studio designer - "Object reference not set to an instance of an object" (Visual Studio 2008)

I recently got tossed some C# code to make some minor cosmetic changes to. When I open up some of the files in Visual Studio though, I get errors saying:

To prevent possible data loss...

The first of these errors is:

Object reference not set to an instance of an object.

I can follow the stack trace fine, but I'm not sure what I really should be looking for in this situation. Also, the end of my stack trace has a call that ends in "PageScroller..ctor()".

Based on a little Google research, I'm assuming that means call the constructor. Is that true?

like image 310
Kivus Avatar asked Jun 23 '09 15:06

Kivus


People also ask

How do I fix object reference is not set to an instance of an object?

To fix "Object reference not set to an instance of an object," you should try running Microsoft Visual Studio as an administrator. You can also try resetting the user data associated with your account or updating Microsoft Visual Studio to the latest version.

How do I fix object reference not set to an instance of an object in VB net?

"instance of object" Means that the object is blank (or in VB speak, "Nothing"). When you are dealing with object variables, you have to create an instance of that object before referencing it. "not set to an " means that you tried to access an object, but there was nothing inside of it for the computer to access.

What does object reference not set to an instance of an object mean in unity?

This error is caused when an object is trying to be used by a script but does not refer to an instance of an object. Resolution. To fix this example we can acquire a reference to an instance of the script using GameObject.


2 Answers

You have a bug in design mode for some custom control, probably PageScroller, and apparently starting from the constructor. Perhaps there's some code in the constructor that returns null in design mode, and the null is not checked for.

like image 125
John Saunders Avatar answered Nov 15 '22 19:11

John Saunders


I occasionally see problems like this. I started moving code from the constructor to the load event and that helped.

like image 26
jon37 Avatar answered Nov 15 '22 19:11

jon37