[英]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. 最近,我扔了一些C#代码来对外观进行一些细微的更改。 When I open up some of the files in Visual Studio though, I get errors saying:
但是,当我在Visual Studio中打开某些文件时,出现错误消息:
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()".
另外,我的堆栈跟踪的末尾有一个以“ PageScroller..ctor()”结尾的调用。
Based on a little Google research, I'm assuming that means call the constructor. 根据Google的一项研究,我假设这意味着调用构造函数。 Is that true?
真的吗?
You have a bug in design mode for some custom control, probably PageScroller, and apparently starting from the constructor. 您在设计模式下存在一些自定义控件(可能是PageScroller)的错误,并且显然是从构造函数开始的。 Perhaps there's some code in the constructor that returns null in design mode, and the null is not checked for.
也许构造函数中有一些代码在设计模式下返回null,并且不检查null。
I occasionally see problems like this. 我偶尔会看到这样的问题。 I started moving code from the constructor to the load event and that helped.
我开始将代码从构造函数移到load事件,这很有帮助。
Make sure that the auto generated 确保自动生成
InitializeComponent();
method is called before trying to reference any object created in designer. 在尝试引用设计器中创建的任何对象之前,将调用方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.