2011-03-21 116 views
3

如何修復Windows窗體設計器中的設計時錯誤?C#Visual Studio 2008 - Windows窗體設計器中的設計時錯誤

當我MyMainForm.cs點擊[設計]頁,彈出的WinForms我得到以下錯誤:

To prevent possible data loss before loading the designer, the following errors must be resolved: 
    The class name '?' is not a valid identifier for this language.  

    Instances of this error (1) 

    1. Hide Call Stack 

    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.CodeTypeDeclarationFromCodeClass(CodeClass vsClass) 
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnNamespacePopulateTypes(Object sender, EventArgs e) 
    at System.CodeDom.CodeNamespace.get_Types() 
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.Parse(TextReader codeStream) 
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.System.CodeDom.Compiler.ICodeParser.Parse(TextReader stream) 
    at System.CodeDom.Compiler.CodeDomProvider.Parse(TextReader codeStream) 
    at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomDocDataAdapter.get_CompileUnit() 
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) 
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) 

以下是MainForm.Designer.cs我的錯誤:

Warning 1 The class name '?' is not a valid identifier for this language.  0 0 (No File Referenced, clicking on this warning does nothing) 
    Error 1 'CCP_Utility.MainForm' does not contain a definition for 'sourceFiles_Click' and no extension method 'sourceFiles_Click' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 84 67 CCP Utility 
    Error 2 'CCP_Utility.MainForm' does not contain a definition for 'targetFolderPath_Click' and no extension method 'targetFolderPath_Click' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 104 67 CCP Utility 
    Error 3 'CCP_Utility.MainForm' does not contain a definition for 'sourceFolderPath_Click' and no extension method 'sourceFolderPath_Click' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 118 63 CCP Utility 
    Error 4 'CCP_Utility.MainForm' does not contain a definition for 'textBoxSourceDir_TextChanged' and no extension method 'textBoxSourceDir_TextChanged' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 128 79 CCP Utility 
    Error 5 'CCP_Utility.MainForm' does not contain a definition for 'textBoxTargetDirectory_TextChanged' and no extension method 'textBoxTargetDirectory_TextChanged' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 138 79 CCP Utility 
    Error 6 'CCP_Utility.MainForm' does not contain a definition for 'button_SaveSearch_Click' and no extension method 'button_SaveSearch_Click' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 151 74 CCP Utility 
    Error 7 'CCP_Utility.MainForm' does not contain a definition for 'groupBox2_Enter' and no extension method 'groupBox2_Enter' accepting a first argument of type 'CCP_Utility.MainForm' could be found (are you missing a using directive or an assembly reference?) C:\Users\bmccarthy\Documents\Visual Studio 2008\Projects\CCP Utility\CCP Utility\MainForm.Designer.cs 164 66 CCP Utility 

讓我知道如果你需要看我的一些代碼,以幫助我

這裏是MainForm.Designer.cs文件代碼:

namespace CCP_Utility 
{ 
    partial class MainForm 
    { 
    /// <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.button_Execute = new System.Windows.Forms.Button(); 
     this.listBox1 = new System.Windows.Forms.ListBox(); 
     this.folderPath = new System.Windows.Forms.Button(); 
     this.label1 = new System.Windows.Forms.Label(); 
     this.targetPath = new System.Windows.Forms.Button(); 
     this.targetFolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); 
     this.label3 = new System.Windows.Forms.Label(); 
     this.textBoxSourceDir = new System.Windows.Forms.TextBox(); 
     this.textBoxTargetDir = new System.Windows.Forms.TextBox(); 
     this.button_SaveSearch = new System.Windows.Forms.Button(); 
     this.groupBox2 = new System.Windows.Forms.GroupBox(); 
     this.buttonClearLog = new System.Windows.Forms.Button(); 
     this.buttonCancelSearch = new System.Windows.Forms.Button(); 
     this.sourceFileOpenFileDialog = new System.Windows.Forms.OpenFileDialog(); 
     this.sourceFolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); 
     this.textBoxSourceFiles = new System.Windows.Forms.TextBox(); 
     this.sourceFiles = new System.Windows.Forms.Button(); 
     this.SuspendLayout(); 
     // 
     // button_Execute 
     // 
     this.button_Execute.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); 
     this.button_Execute.Location = new System.Drawing.Point(12, 148); 
     this.button_Execute.Name = "button_Execute"; 
     this.button_Execute.Size = new System.Drawing.Size(114, 23); 
     this.button_Execute.TabIndex = 11; 
     this.button_Execute.Text = "Search"; 
     this.button_Execute.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.button_Execute.UseVisualStyleBackColor = true; 
     // 
     // listBox1 
     // 
     this.listBox1.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.listBox1.Font = new System.Drawing.Font("Calibri", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.listBox1.FormattingEnabled = true; 
     this.listBox1.ItemHeight = 18; 
     this.listBox1.Location = new System.Drawing.Point(21, 220); 
     this.listBox1.Name = "listBox1"; 
     this.listBox1.Size = new System.Drawing.Size(743, 184); 
     this.listBox1.TabIndex = 15; 
     this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); 
     // 
     // folderPath 
     // 
     this.folderPath.Location = new System.Drawing.Point(12, 59); 
     this.folderPath.Name = "folderPath"; 
     this.folderPath.Size = new System.Drawing.Size(117, 23); 
     this.folderPath.TabIndex = 1; 
     this.folderPath.Text = "Source Directory"; 
     this.folderPath.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.folderPath.UseVisualStyleBackColor = true; 
     this.folderPath.Click += new System.EventHandler(this.sourceFiles_Click); 
     // 
     // label1 
     // 
     this.label1.AutoSize = true; 
     this.label1.Location = new System.Drawing.Point(12, 94); 
     this.label1.Name = "label1"; 
     this.label1.Size = new System.Drawing.Size(130, 13); 
     this.label1.TabIndex = 3; 
     this.label1.Text = "Choose the Target Folder:"; 
     // 
     // targetPath 
     // 
     this.targetPath.Location = new System.Drawing.Point(12, 110); 
     this.targetPath.Name = "targetPath"; 
     this.targetPath.Size = new System.Drawing.Size(114, 23); 
     this.targetPath.TabIndex = 3; 
     this.targetPath.Text = "Target Directory"; 
     this.targetPath.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.targetPath.UseVisualStyleBackColor = true; 
     this.targetPath.Click += new System.EventHandler(this.targetFolderPath_Click); 
     // 
     // targetFolderBrowserDialog 
     // 
     this.targetFolderBrowserDialog.Description = "targetFolderBrowserDialog"; 
     // 
     // label3 
     // 
     this.label3.AutoSize = true; 
     this.label3.Location = new System.Drawing.Point(12, 43); 
     this.label3.Name = "label3"; 
     this.label3.Size = new System.Drawing.Size(133, 13); 
     this.label3.TabIndex = 6; 
     this.label3.Text = "Choose the Source Folder:"; 
     this.label3.Click += new System.EventHandler(this.sourceFolderPath_Click); 
     // 
     // textBoxSourceDir 
     // 
     this.textBoxSourceDir.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right))); 
     this.textBoxSourceDir.Location = new System.Drawing.Point(135, 59); 
     this.textBoxSourceDir.Name = "textBoxSourceDir"; 
     this.textBoxSourceDir.Size = new System.Drawing.Size(395, 20); 
     this.textBoxSourceDir.TabIndex = 2; 
     this.textBoxSourceDir.TextChanged += new System.EventHandler(this.textBoxSourceDir_TextChanged); 
     // 
     // textBoxTargetDir 
     // 
     this.textBoxTargetDir.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right))); 
     this.textBoxTargetDir.Location = new System.Drawing.Point(135, 110); 
     this.textBoxTargetDir.Name = "textBoxTargetDir"; 
     this.textBoxTargetDir.Size = new System.Drawing.Size(395, 20); 
     this.textBoxTargetDir.TabIndex = 4; 
     this.textBoxTargetDir.TextChanged += new System.EventHandler(this.textBoxTargetDirectory_TextChanged); 
     // 
     // button_SaveSearch 
     // 
     this.button_SaveSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.button_SaveSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); 
     this.button_SaveSearch.Location = new System.Drawing.Point(361, 177); 
     this.button_SaveSearch.Name = "button_SaveSearch"; 
     this.button_SaveSearch.Size = new System.Drawing.Size(151, 23); 
     this.button_SaveSearch.TabIndex = 12; 
     this.button_SaveSearch.Text = "Save Search"; 
     this.button_SaveSearch.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.button_SaveSearch.UseVisualStyleBackColor = true; 
     this.button_SaveSearch.Click += new System.EventHandler(this.button_SaveSearch_Click); 
     // 
     // groupBox2 
     // 
     this.groupBox2.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.groupBox2.Location = new System.Drawing.Point(15, 206); 
     this.groupBox2.Name = "groupBox2"; 
     this.groupBox2.Size = new System.Drawing.Size(762, 206); 
     this.groupBox2.TabIndex = 20; 
     this.groupBox2.TabStop = false; 
     this.groupBox2.Text = "Logging Window"; 
     this.groupBox2.Enter += new System.EventHandler(this.groupBox2_Enter); 
     // 
     // buttonClearLog 
     // 
     this.buttonClearLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.buttonClearLog.Location = new System.Drawing.Point(361, 148); 
     this.buttonClearLog.Name = "buttonClearLog"; 
     this.buttonClearLog.Size = new System.Drawing.Size(151, 23); 
     this.buttonClearLog.TabIndex = 13; 
     this.buttonClearLog.Text = "Clear Log"; 
     this.buttonClearLog.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.buttonClearLog.UseVisualStyleBackColor = true; 
     // this.buttonClearLog.Click += new System.EventHandler(this.buttonClearLog_Click); 
     // 
     // buttonCancelSearch 
     // 
     this.buttonCancelSearch.Location = new System.Drawing.Point(135, 148); 
     this.buttonCancelSearch.Name = "buttonCancelSearch"; 
     this.buttonCancelSearch.Size = new System.Drawing.Size(111, 23); 
     this.buttonCancelSearch.TabIndex = 21; 
     this.buttonCancelSearch.Text = "Cancel Search"; 
     this.buttonCancelSearch.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.buttonCancelSearch.UseVisualStyleBackColor = true; 
     // this.buttonCancelSearch.Click += new System.EventHandler(this.buttonCancelSearch_Click); 
     // 
     // sourceFileOpenFileDialog 
     // 
     this.sourceFileOpenFileDialog.DefaultExt = "xlsx"; 
     this.sourceFileOpenFileDialog.InitialDirectory = "I:\\CommissisionReconciliation\\Review\\"; 
     // 
     // sourceFolderBrowserDialog 
     // 
     // this.sourceFolderBrowserDialog.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest); 
     // 
     // textBoxSourceFiles 
     // 
     this.textBoxSourceFiles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right))); 
     this.textBoxSourceFiles.Location = new System.Drawing.Point(135, 12); 
     this.textBoxSourceFiles.Name = "textBoxSourceFiles"; 
     this.textBoxSourceFiles.Size = new System.Drawing.Size(395, 20); 
     this.textBoxSourceFiles.TabIndex = 22; 
     this.textBoxSourceFiles.TextChanged += new System.EventHandler(this.textBoxSourceFiles_TextChanged); 
     // 
     // sourceFiles 
     // 
     this.sourceFiles.Location = new System.Drawing.Point(12, 12); 
     this.sourceFiles.Name = "sourceFiles"; 
     this.sourceFiles.Size = new System.Drawing.Size(117, 23); 
     this.sourceFiles.TabIndex = 23; 
     this.sourceFiles.Text = "Select Files"; 
     this.sourceFiles.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     this.sourceFiles.UseVisualStyleBackColor = true; 
     this.sourceFiles.Click += new System.EventHandler(this.sourceFiles_Click_1); 
     // 
     // MainForm 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(841, 424); 
     this.Controls.Add(this.sourceFiles); 
     this.Controls.Add(this.textBoxSourceFiles); 
     this.Controls.Add(this.buttonCancelSearch); 
     this.Controls.Add(this.buttonClearLog); 
     this.Controls.Add(this.button_SaveSearch); 
     this.Controls.Add(this.textBoxTargetDir); 
     this.Controls.Add(this.textBoxSourceDir); 
     this.Controls.Add(this.label3); 
     this.Controls.Add(this.targetPath); 
     this.Controls.Add(this.label1); 
     this.Controls.Add(this.folderPath); 
     this.Controls.Add(this.button_Execute); 
     this.Controls.Add(this.listBox1); 
     this.Controls.Add(this.groupBox2); 
     this.MinimumSize = new System.Drawing.Size(857, 361); 
     this.Name = "MainForm"; 
     this.Text = "CCP Commission File Consolidation Process Utility v1.0.0"; 
     // this.Load += new System.EventHandler(this.Form1_Load); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 

    #endregion 

    private System.Windows.Forms.Button button_Execute; 
    private System.Windows.Forms.ListBox listBox1; 
    private System.Windows.Forms.Button folderPath; 
    private System.Windows.Forms.Label label1; 
    private System.Windows.Forms.Button targetPath; 
    private System.Windows.Forms.FolderBrowserDialog targetFolderBrowserDialog; 
    private System.Windows.Forms.Label label3; 
    private System.Windows.Forms.TextBox textBoxSourceDir; 
    private System.Windows.Forms.TextBox textBoxTargetDir; 
    private System.Windows.Forms.Button button_SaveSearch; 
    private System.Windows.Forms.GroupBox groupBox2; 
    private System.Windows.Forms.Button buttonClearLog; 
    private System.Windows.Forms.Button buttonCancelSearch; 
    private System.Windows.Forms.OpenFileDialog sourceFileOpenFileDialog; 
    private System.Windows.Forms.FolderBrowserDialog sourceFolderBrowserDialog; 
    private System.Windows.Forms.TextBox textBoxSourceFiles; 
    private System.Windows.Forms.Button sourceFiles; 
    } 
} 

回答

5

嘗試關閉解決方案,重新打開它,然後打開表單。根據我的經驗,這個錯誤可能會消失,只會在以後再次出現。

如果錯誤沒有消失,然後根據
http://connect.microsoft.com/VisualStudio/feedback/details/497218/the-class-name-is-not-a-valid-identifier-for-this-language-can-reproduce-w-vs-2008

http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/f2c1a027-3e49-4f7f-a4c2-c91a8fde25fc
你可能有太多的右括號的地方。

+0

@JudagSali,謝謝你的回覆。我添加了我的錯誤和設計器代碼。讓我知道你的想法。 – 2011-03-22 12:43:54

+1

@JudagSali,謝謝你的迴應。我從MainForm.cs文件中刪除了一個括號,關閉了該文件,並重新打開它,所有的錯誤消失了,設計器加載好了!謝謝! – 2011-03-22 13:08:52

+0

你救了我的一天 – AbiusX 2011-09-06 20:20:15

1

我有這個錯誤,這是因爲我有一個無效的變量名稱(以數字開始)。希望這可以幫助任何人解決這個問題。

0

嘗試關閉解決方案,清潔液和重建的解決方案,並將其proble會去,主窗體設計器將可見...

,如果仍然是there..just去n檢查最後修改ü在代碼中完成..在那裏你可能有太多的右括號。

希望這會爲你工作..

0

在我來說,我已經添加了一個文本文件,默認生成操作爲內容。當我改變這個建立動作時,沒有那個錯誤「班級名稱」?不是此語言的有效標識符。「離開了。

0

通常的做法是在設計代碼中查找錯誤,但我發現這是無益的,因爲在那裏一切都正確(設計器生成的良好代碼,我沒有觸及它)。

該錯誤原來是在我自己的代碼中(一個嘗試失去了花括號)。有趣的是,我的代碼中的錯誤破壞了Designer。我預計它是獨立的(在一定程度上)。

相關問題