该变量未声明或从未在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase 中分配

发布于 2024-07-19 08:15:49 字数 1694 浏览 5 评论 0原文

我是 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 my ProtocolTabPage.
  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哭了丶谁疼 2024-07-26 08:15:49

乍一看,您似乎正在尝试使用类型名称作为变量名称,这通常应该避免。 在您的 ProtocolPanel 实例化中,尝试:

ProtocolPanel myProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();

然后您可以将对“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:

ProtocolPanel myProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();

Then you can just change all of those calls to "This.ProtocolPanel" to "myProtocolPanel."

也只是曾经 2024-07-26 08:15:49

这是我在 5 分钟内的猜测...您所看到的调用堆栈是当 .Net 不知道如何序列化/反序列化 gui 类的成员时所得到的。

请尝试以下操作:

[Browsable(false)]
ProtocolPanel ProtocolPanel {get {...} set {...} }

如果仍然不起作用,请打开表单的 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:

[Browsable(false)]
ProtocolPanel ProtocolPanel {get {...} set {...} }

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.

極樂鬼 2024-07-26 08:15:49

我的猜测,因为我也遇到过类似的问题:

您的 ProtocolPanel 类在其构造函数中执行一些在设计时不起作用的操作。 例如,您正在读取不存在的设置文件,这会引发异常吗? 或者你主动序列化一些不可序列化的东西?

在我的构造函数中,有访问模型的初始化代码,该代码在设计时不存在。 我在构造函数路径中引入了以下代码,这有帮助:

if (DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{               
    return;   //in design mode do not initialize anything (accessing the model here may cause troubles)
}

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:

if (DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{               
    return;   //in design mode do not initialize anything (accessing the model here may cause troubles)
}
你对谁都笑 2024-07-26 08:15:49

我遇到了同样的错误并打开了 *.resx 文件。 字符串包含没有值的 String1 变量。 我删除了它,它强制保存并修复了问题(使用 Visual Studio 2010)

  1. 在解决方案资源管理器中展开有问题的表单
  2. 双击 *.resx 文件
  3. 从下拉列表中选择字符串
  4. 右键单击 String1 并选择删除
  5. 确定保存然后关闭*.resx 并重新打开表单

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)

  1. In Solution Explorer expand the offending form
  2. Double-Click the *.resx file
  3. Select Strings from the dropdown
  4. Right-click String1 and select Delete
  5. OK to save then close the *.resx and reopen the form
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文