Search code examples
c#winformsvisual-studio-2017designer

The variable 'control' is either undeclared or was never assigned - Except it is, and the application compiles


My designer view started to throw up this error today. However, the application compiles without error and the controls are useable.

The custom control is defined in the designer correctly. If i click "ignore and continue" the designer loads up fine, but the control mentioned is missing.

So far I have tried:

Cleaning, rebuilding then restarting visual studio hasn't worked.

I haven't made any changes since using it yesterday, then walking into the office today.

My constructors are

public CalendarWindow(MainWindow owner)
{
    InitializeComponent();
    this._owner = owner;
}

public CalendarWindow(int job, int visit, DataTable customer, DataTable address)
{

    InitializeComponent();

    this.addressDetails = address;
    this.customerDetails = customer;
    this.visitID = visit;
    jobID = job;
}

and inside InitializeComponent() in designer.cs the controls are declared

// 
// panel1
// 
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
| System.Windows.Forms.AnchorStyles.Left) 
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.calendar4); \\designer "error" points to here
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.calendar3); \\designer "error" points to here
this.panel1.Controls.Add(this.calendar2); \\designer "error" points to here    
this.panel1.Controls.Add(this.calendar1); \\designer "error" points to here
this.panel1.Controls.Add(this.label2);
this.panel1.Location = new System.Drawing.Point(218, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(873, 628);
this.panel1.TabIndex = 10;
this.panel1.MouseDown += new 
System.Windows.Forms.MouseEventHandler(this.calendar1_MouseDown);

enter image description here


Solution

  • Looks like I've managed to solve this problem.

    While the compiler didn't have any problems compiling the code and running the application, it didn't like some code within the control itself.

    I only managed to catch this because i attempted to add the same control to the form after hitting "ignore and continue" at which point it refused to add it and provided me with direction to what was causing the problem, which happened to be in a class that wasn't part of the control but was used by it.

    Correcting that error solved the problem.

    I'm no wiser as to why it would compile and run without problems, yet the errors fed back made no reference to the offending artifact.