views:

375

answers:

3
+1  Q: 

C# Designer error

Hello,

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 ?

+1  A: 

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."

AllenG
...but ProtocolPanel is a ControlPanel Type, he didn't mention a ProtocolPanel type in his description. :(
STW
There is nothing technically wrong with using the type name as the field/property name. Eric Lippert has a post about this specifically, he refers to it as the "Color Color" problem.
Ed Swangren
A: 

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.

Jason D
A: 

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)
}
Marcel