该变量未声明或从未在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase 中分配
我是 C# 新手,所以如果我问愚蠢的问题,请原谅我...
这是我的问题:
- 我有一个继承自“
TabPage
”的类“ProtocolTabPage
” ”。 - 我有一个继承自“
Panel
”的“ControlPanel
”。 - 我有一个由我的
ProtocolTabPage
实例化的ControlPanel
。 - 我的两个类都位于命名空间“
AutoTestProtocols.Interface
”中。
在 ProtocolTabPage[Design]
中,我有以下错误:
“变量“ProtocolPanel”未声明或从未声明过 已分配。
在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager 经理,字符串异常文本,字符串helpLink)位于 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager 经理、字符串名称、CodeExpression 表达式)位于 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager 经理、字符串名称、CodeExpression 表达式)位于 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager 经理,CodeStatement 声明)”
但是,在我的 ProtocolTabPage.Designer
中,我有
[...]
this.ProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();
[...]
this.splitContainer1.Panel2.Controls.Add(this.ProtocolPanel);
[...]
this.ProtocolPanel.AutoScroll = true;
this.ProtocolPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ProtocolPanel.Location = new System.Drawing.Point(0, 0);
this.ProtocolPanel.Name = "ProtocolPanel";
this.ProtocolPanel.Size = new System.Drawing.Size(696, 700);
this.ProtocolPanel.TabIndex = 0;
[...]
private AutoTestProtocols.Interface.ControlPanel ProtocolPanel;"
什么问题?
I'm a newbie to C# so please excuse me if I ask dumb questions...
Here is my problem :
- I have a class "
ProtocolTabPage
" that inherits from "TabPage
". - I have a "
ControlPanel
" that inherits from "Panel
". - I have a
ControlPanel
instanced by myProtocolTabPage
. - Both my classes are in the namespace "
AutoTestProtocols.Interface
".
In the ProtocolTabPage[Design]
, I have the following errors :
"The variable 'ProtocolPanel' is either undeclared or was never
assigned.at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)"
Though, in my ProtocolTabPage.Designer
, I have
[...]
this.ProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();
[...]
this.splitContainer1.Panel2.Controls.Add(this.ProtocolPanel);
[...]
this.ProtocolPanel.AutoScroll = true;
this.ProtocolPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ProtocolPanel.Location = new System.Drawing.Point(0, 0);
this.ProtocolPanel.Name = "ProtocolPanel";
this.ProtocolPanel.Size = new System.Drawing.Size(696, 700);
this.ProtocolPanel.TabIndex = 0;
[...]
private AutoTestProtocols.Interface.ControlPanel ProtocolPanel;"
What's wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
乍一看,您似乎正在尝试使用类型名称作为变量名称,这通常应该避免。 在您的 ProtocolPanel 实例化中,尝试:
然后您可以将对“This.ProtocolPanel”的所有调用更改为“myProtocolPanel”。
Just at first blush it looks like you're trying to use a Type name as a variable name, which should generally be avoided. In your ProtocolPanel instantiation, try:
Then you can just change all of those calls to "This.ProtocolPanel" to "myProtocolPanel."
这是我在 5 分钟内的猜测...您所看到的调用堆栈是当 .Net 不知道如何序列化/反序列化 gui 类的成员时所得到的。
请尝试以下操作:
如果仍然不起作用,请打开表单的 resx,然后单击“字符串”(类型)下拉列表。 单击“其他”,查看是否有与其中列出的 ProtocolPanel 相关的任何二进制序列化数据。 如果有,请删除它们。
Here's my guess in 5 minutes ... The call stack you're seeing is what you get when the .Net doesn't know how to serialize/deserialize a member of a gui class.
Try the following:
If it still doesn't work, open the resx for the form and click on the "Strings"(type) drop down. Click "Other" and see if there are any binary serialization data related to ProtocolPanel listed there. If so, delete them.
我的猜测,因为我也遇到过类似的问题:
您的 ProtocolPanel 类在其构造函数中执行一些在设计时不起作用的操作。 例如,您正在读取不存在的设置文件,这会引发异常吗? 或者你主动序列化一些不可序列化的东西?
在我的构造函数中,有访问模型的初始化代码,该代码在设计时不存在。 我在构造函数路径中引入了以下代码,这有帮助:
My guess, as I had a similar problem:
Your ProtocolPanel class does something in it's constructor, that does not work at design time. For example you are reading a settings file that is not there and this throws an exception? Or you actively serialize something that is not serializable?
In my constructor, there was initialization code that accessed a model, which was not present at design time. I introduced the following code in the constructor path, which helped:
我遇到了同样的错误并打开了 *.resx 文件。 字符串包含没有值的 String1 变量。 我删除了它,它强制保存并修复了问题(使用 Visual Studio 2010)
I had the same error and opened the *.resx file. The strings contains String1 variable with no value. I deleted this and it forced a save and fixed the problem (using Visual Studio 2010)