简体   繁体   English

使用Visual Studio设计器-“对象引用未设置为对象的实例”(Visual Studio 2008)

[英]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.

相关问题 错误:对象引用未设置为对象企业架构师和Visual Studio的实例 - Error:Object reference not set to an instance of an object enterprise architect and visual studio Visual Studio XAML设计窗口错误:对象引用未设置为对象的实例 - Visual Studio XAML Design Window Error: Object reference not set to an instance of an object Visual Studio 2017 和 2019 SqlDataSource“无法连接 - 未将对象引用设置为对象的实例” - Visual Studio 2017 & 2019 SqlDataSource "Cannot Connect - Object Reference not set to an instance of an object" Visual Studio 2017:加载项目时“对象引用未设置到对象的实例” - Visual Studio 2017: "Object reference not set to an instance of an object" while loading the project 将数据从Excel导入到Visual Studio dataGridView。 得到此错误对象引用未设置为对象的实例 - Importing data from Excel to Visual studio dataGridView. Get this error Object reference not set to an instance of an object Visual Studio WinForms设计器不实例化对象 - Visual Studio WinForms designer does not instantiate object 当我尝试添加参考时,Visual Studio 得到这个:Instance object set as constant - Visual studio when i try to add reference get this : Instance object set as constant Visual Studio 2008设计器中的方形鼠标指针 - Square mouse pointer in Visual Studio 2008 designer Visual Studio 2008在访问表单设计器时出错 - visual studio 2008 error at accessing form designer C#/Visual Studio 尝试更改随机数组的内容并获取“未将对象引用设置为对象的实例”。 错误 - C#/Visual Studio trying to change the content of random array and getting 'Object reference not set to an instance of an object.' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM