C# Visual Studio Designer无法打开文件,尽管它是文件中的第一个也是唯一一个类

C# Visual Studio Designer无法打开文件,尽管它是文件中的第一个也是唯一一个类,c#,winforms,visual-studio,entity-framework,debugging,C#,Winforms,Visual Studio,Entity Framework,Debugging,然而,某些不兼容的行为也可能导致此问题 在我的例子中,不兼容的行为是由实体框架上一些可能奇怪的(混乱的映射)引起的 我已经做了尽职调查,以确保数据模型和EF模型之间一一对应(甚至重新创建了两次) 当我注释掉某段代码时,项目将生成并运行 public partial class TestForm : SecureForm { private myEntities _db = new myEntities(); public TestForm() { Ini

然而,某些不兼容的行为也可能导致此问题

在我的例子中,不兼容的行为是由实体框架上一些可能奇怪的(混乱的映射)引起的

我已经做了尽职调查,以确保数据模型和EF模型之间一一对应(甚至重新创建了两次)

当我注释掉某段代码时,项目将生成并运行

public partial class TestForm : SecureForm
{
    private myEntities _db = new myEntities();

    public TestForm()
    {
        InitializeComponent();

        PopulateTestsList();
    }

    private void PopulateTestsList()
    {
        listViewTypes.Items.Clear();

        var query = from q in _db.Types orderby q.TypeName select q;

        foreach (Type dt in query)
        {
            ListViewItem lvi = new ListViewItem(new string[]
            {
            dt.TypeName
            });
            lvi.Tag = dt;
            listViewTypes.Items.Add(lvi);
        }

    }

    private void buttonAdd_Click(object sender, EventArgs e)
    {
        TestEditForm myEditForm = new TestEditForm(_db);
        if (myEditForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            PopulateTestsList();
    }

    private void buttonEdit_Click(object sender, EventArgs e)
    {
        if (listViewTypes.SelectedItems.Count > 0)
        {
            Test tsdt = listViewTypes.SelectedItems[0].Tag as Test;
            if (myEditForm != null)
            {
                TestEditForm myEditForm = new TestEditForm(_db, mysForm);
                if (myEditForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    PopulateTestsList();
            }
        }
    }
}
它仍然没有出现在设计师面前

这是designer.cs供参考

partial class TestForm
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.buttonDelete = new System.Windows.Forms.Button();
        this.buttonEdit = new System.Windows.Forms.Button();
        this.buttonAdd = new System.Windows.Forms.Button();
        this.listViewTypes = new System.Windows.Forms.ListView();
        this.columnName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        // 
        // buttonDelete
        // 
        this.buttonDelete.Location = new System.Drawing.Point(304, 86);
        this.buttonDelete.Name = "buttonDelete";
        this.buttonDelete.Size = new System.Drawing.Size(75, 23);
        this.buttonDelete.TabIndex = 9;
        this.buttonDelete.Text = "Delete";
        this.buttonDelete.UseVisualStyleBackColor = true;
        this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
        // 
        // buttonEdit
        // 
        this.buttonEdit.Location = new System.Drawing.Point(304, 56);
        this.buttonEdit.Name = "buttonEdit";
        this.buttonEdit.Size = new System.Drawing.Size(75, 23);
        this.buttonEdit.TabIndex = 8;
        this.buttonEdit.Text = "Edit";
        this.buttonEdit.UseVisualStyleBackColor = true;
        this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
        // 
        // buttonAdd
        // 
        this.buttonAdd.Location = new System.Drawing.Point(304, 26);
        this.buttonAdd.Name = "buttonAdd";
        this.buttonAdd.Size = new System.Drawing.Size(75, 23);
        this.buttonAdd.TabIndex = 7;
        this.buttonAdd.Text = "Add";
        this.buttonAdd.UseVisualStyleBackColor = true;
        this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
        // 
        // listViewTypes
        // 
        this.listViewTypes.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.columnName});
        this.listViewTypes.FullRowSelect = true;
        this.listViewTypes.HideSelection = false;
        this.listViewTypes.Location = new System.Drawing.Point(12, 26);
        this.listViewTypes.Name = "listViewTypes";
        this.listViewTypes.Size = new System.Drawing.Size(274, 205);
        this.listViewTypes.TabIndex = 6;
        this.listViewTypes.UseCompatibleStateImageBehavior = false;
        this.listViewTypes.View = System.Windows.Forms.View.Details;
        // 
        // columnName
        // 
        this.columnName.Text = "Document Type";
        this.columnName.Width = 270;
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(12, 10);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(79, 13);
        this.label1.TabIndex = 5;
        this.label1.Text = "Test Standards";
        // 
        // TestsForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(395, 242);
        this.Controls.Add(this.buttonDelete);
        this.Controls.Add(this.buttonEdit);
        this.Controls.Add(this.buttonAdd);
        this.Controls.Add(this.listViewTypes);
        this.Controls.Add(this.label1);
        this.Name = "TestsForm";
        this.Opacity = 1D;
        this.Text = "Test Standards";
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Button buttonDelete;
    private System.Windows.Forms.Button buttonEdit;
    private System.Windows.Forms.Button buttonAdd;
    private System.Windows.Forms.ListView listViewTypes;
    private System.Windows.Forms.ColumnHeader columnName;
    private System.Windows.Forms.Label label1;
}
部分类TestForm
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
this.buttonDelete=new System.Windows.Forms.Button();
this.buttonEdit=new System.Windows.Forms.Button();
this.buttonad=new System.Windows.Forms.Button();
this.listViewTypes=new System.Windows.Forms.ListView();
this.columnName=((System.Windows.Forms.ColumnHeader)(新的System.Windows.Forms.ColumnHeader());
this.label1=new System.Windows.Forms.Label();
这个.SuspendLayout();
// 
//钮扣删除
// 
this.buttonDelete.Location=新系统图纸点(304,86);
this.buttonDelete.Name=“buttonDelete”;
this.buttonDelete.Size=新系统图纸尺寸(75,23);
this.buttonDelete.TabIndex=9;
this.buttonDelete.Text=“删除”;
this.buttonDelete.UseVisualStyleBackColor=true;
this.buttonDelete.Click+=新系统.EventHandler(this.buttonDelete\u Click);
// 
//扣紧
// 
this.buttonEdit.Location=新系统图点(304,56);
this.buttonEdit.Name=“buttonEdit”;
this.buttonEdit.Size=新系统图尺寸(75,23);
this.buttonEdit.TabIndex=8;
this.buttonEdit.Text=“编辑”;
this.buttonEdit.UseVisualStyleBackColor=true;
this.buttonEdit.Click+=new System.EventHandler(this.buttonEdit\u Click);
// 
//钮扣
// 
this.buttonAdd.Location=新系统图纸点(304,26);
this.buttonAdd.Name=“buttonAdd”;
this.buttonAdd.Size=新系统图纸尺寸(75,23);
this.buttonad.TabIndex=7;
this.buttonad.Text=“添加”;
this.buttonad.UseVisualStyleBackColor=true;
this.buttonAdd.Click+=新系统.EventHandler(this.buttonAdd\u Click);
// 
//listViewTypes
// 
this.listViewTypes.Columns.AddRange(新的System.Windows.Forms.ColumnHeader[]{
此字段为.columnName});
this.listViewTypes.FullRowSelect=true;
this.listViewTypes.HideSelection=false;
this.listViewTypes.Location=新系统.Drawing.Point(12,26);
this.listViewTypes.Name=“listViewTypes”;
this.listViewTypes.Size=新系统.Drawing.Size(274205);
this.listViewTypes.TabIndex=6;
this.listViewTypes.UseCompatibleStateImageBehavior=false;
this.listViewTypes.View=System.Windows.Forms.View.Details;
// 
//列名
// 
this.columnName.Text=“文档类型”;
this.columnName.Width=270;
// 
//标签1
// 
this.label1.AutoSize=true;
this.label1.Location=新系统图纸点(12,10);
this.label1.Name=“label1”;
this.label1.Size=新系统图纸尺寸(79,13);
this.label1.TabIndex=5;
this.label1.Text=“测试标准”;
// 
//测试表单
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(395242);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.listViewTypes);
this.Controls.Add(this.label1);
this.Name=“TestsForm”;
不透明度=1D;
此.Text=“测试标准”;
此选项为.resume布局(false);
这个。执行布局();
}
#端区
private System.Windows.Forms.Button按钮删除;
private System.Windows.Forms.Button buttonEdit;
private System.Windows.Forms.Button按钮添加;
private System.Windows.Forms.ListView listViewTypes;
private System.Windows.Forms.ColumnHeader columnName;
private System.Windows.Forms.label1;
}
代码分析显示缺少表单(MSBuild没有)。MSBUILD将表单编译成一个exe,该exe有点失效(在损坏的实体上)

该实体具有名称和ID属性。名称和ID都正确映射,集合被复数化并加载到列表中

如何识别损坏的实体和/或


如何识别代码中的不兼容行为

您可以发布整个类文件吗?嘿,Ron,刚刚发布了。您共享的代码中没有问题。问题可能存在于
SecureForm
…SecureForm是一个跨所有表单实现的经过测试的接口。我在这里没有做任何不同的事情(与其他形式相反)好的观点虽然奇怪,但重新创建了整个形式。工作。