C# 变量“control”未声明或从未分配过-除非它是,并且应用程序编译

C# 变量“control”未声明或从未分配过-除非它是,并且应用程序编译,c#,winforms,visual-studio-2017,designer,C#,Winforms,Visual Studio 2017,Designer,我的designer视图今天开始抛出这个错误。但是,应用程序编译时不会出错,并且控件可用 自定义控件已在设计器中正确定义。如果单击“忽略”并继续,设计器将正常加载,但缺少所提到的控件 到目前为止,我已经尝试: 清理、重建然后重新启动visual studio都不起作用 自从昨天使用它,今天走进办公室以来,我没有做任何改变 我的构造函数是 public CalendarWindow(MainWindow owner) { InitializeComponent(); this._o

我的designer视图今天开始抛出这个错误。但是,应用程序编译时不会出错,并且控件可用

自定义控件已在设计器中正确定义。如果单击“忽略”并继续,设计器将正常加载,但缺少所提到的控件

到目前为止,我已经尝试:

清理、重建然后重新启动visual studio都不起作用

自从昨天使用它,今天走进办公室以来,我没有做任何改变

我的构造函数是

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;
}
在designer.cs中的InitializeComponent中声明控件

// 
// 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);

看来我已经解决了这个问题

虽然编译器在编译代码和运行应用程序时没有任何问题,但它不喜欢控件本身中的某些代码

我之所以能够捕捉到这一点,是因为我试图在点击ignore并继续之后将同一个控件添加到表单中,但表单拒绝添加该控件,并向我提供了导致问题的方向,问题发生在一个类中,该类不是控件的一部分,但被它使用

纠正那个错误解决了问题


我不知道为什么它编译和运行时不会出现问题,但是反馈的错误没有提到有问题的工件。

我也遇到了同样的问题,我已经修复了它。实际上,VisualStudio只适用于X86控件,您不能在X64模式下创建用户控件并使用它

您应该在任何CPU模式下添加一个新类库并构建该库。然后你可以在你的项目中添加它的DLL,它就可以工作了

如果没有,则必须转到Configuration manager,将活动解决方案平台设置为X64,并对所有子项目执行此操作。 请记住,必须选中“生成”选项。
然后转到类库的属性并单击build选项卡。然后将平台目标设置为任何CPU。

显示错误出现的代码,没有任何错误,我们只能guess@EpicKip没有代码可显示。这是一个看起来很常见的设计视图问题,但是到目前为止,这里的解决方案都不起作用。你说它给出了一个错误,通常这个错误指向一个位置。而且,如果我们不能接近你,我们也帮不了你reproducing@EpicKip错误指向一行没有出错的代码。这是IDE本身的一个错误,代码很好,否则它将无法编译和工作。自定义控件消失的事实意味着有问题:如果这是一个IDE错误,如何重现它来帮助您?