我是C#的新手,所以如果我提出愚蠢的问题,请原谅我......
这是我的问题:
在ProtocolTabPage [Design]中,我有以下错误:
“变量'ProtocolPanel'要么未声明,要么从未被分配。
在System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager,String exceptionText,String helpLink) 在System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager,String name,CodeExpression expression) 在System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager,String name,CodeExpression expression) 在System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager,CodeStatement statement)“
虽然,在我的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;"
怎么了?
答案 0 :(得分:1)
乍一看,您似乎正在尝试使用Type名称作为变量名称,这通常应该避免。在ProtocolPanel实例化中,尝试:
ProtocolPanel myProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();
然后你可以将所有这些调用更改为“This.ProtocolPanel”到“myProtocolPanel”。
答案 1 :(得分:1)
这是我在5分钟内的猜测...当你.Net不知道如何序列化/反序列化gui类的成员时,你看到的调用栈就是你所获得的。
尝试以下方法:
[Browsable(false)]
ProtocolPanel ProtocolPanel {get {...} set {...} }
如果仍然无效,请打开表单的resx,然后单击“字符串”(类型)下拉列表。单击“其他”,查看是否有与此处列出的ProtocolPanel相关的任何二进制序列化数据。如果是,请删除它们。
答案 2 :(得分:0)
我的猜测,因为我遇到了类似的问题:
您的ProtocolPanel类在其构造函数中执行某些操作,但在设计时不起作用。例如,您正在读取不存在的设置文件,这会引发异常?或者您主动序列化不可序列化的东西?
在我的构造函数中,存在访问模型的初始化代码,该模型在设计时不存在。我在构造函数路径中引入了以下代码,这有助于:
if (DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
return; //in design mode do not initialize anything (accessing the model here may cause troubles)
}
答案 3 :(得分:0)
我遇到了同样的错误并打开了* .resx文件。字符串包含没有值的String1变量。我删除了这个并强制保存并修复了问题(使用Visual Studio 2010)