如何修复Windows窗体设计器中的设计时错误?
当我点击MyMainForm.cs [Design]页面调出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;
}
}
答案 0 :(得分: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
你可能在某处有太多的右括号。
答案 1 :(得分:1)
我遇到了这个错误,因为我的变量名称无效(以数字开头)。希望这有助于其他任何人遇到这个问题。
答案 2 :(得分:0)
尝试关闭解决方案,清理解决方案并重新构建解决方案,问题就出现了,主表单设计器将会显示...
如果仍然存在..请检查你在代码中完成的最后一次修改。在那里你可能有太多的右括号。
希望这对你有用..
答案 3 :(得分:0)
在我的情况下,我添加了一个文本文件,默认构建操作是内容。当我改变它以构建动作时没有错误“类名'?'不是此语言的有效标识符。“走了。
答案 4 :(得分:0)
通常的方法是在设计代码中查找错误,但我发现这没有用,因为那里的一切都是正确的(Designer生成了良好的代码而我没有触及它)。
错误结果出现在我自己的代码中(尝试缺少大括号)。有趣的是,我的代码中的错误打破了Designer。我希望它是独立的(在某种程度上)。