C# Visual Studio 2008 - Design-Time Error in the Windows Forms Designer

10,418

Solution 1

Try closing the solution, re-opening it and then opening the form. In my experience, the error may go away, only to re-surface again later.

If the error doesn't go away, then according to
http://connect.microsoft.com/VisualStudio/feedback/details/497218/the-class-name-is-not-a-valid-identifier-for-this-language-can-reproduce-w-vs-2008
and
http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/f2c1a027-3e49-4f7f-a4c2-c91a8fde25fc
you may have too many closing brackets somewhere.

Solution 2

I had this error, and it was because i had an invalid variable name (started with a number). Hope this helps anyone else how may run into this issue.

Share:
10,418
Brian McCarthy
Author by

Brian McCarthy

Noob .NET Developer and UF Gator Graduate from sunny Tampa, FL using C# & VB w/ Visual Studio 2017 Premium. I also do Search Engine Optimization Consulting and Wordpress configurations. Feel free to contact me on: LinkedIn, Google +, or Facebook :) Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" -Brian Kernighan from "Elements of Programming Style

Updated on June 27, 2022

Comments

  • Brian McCarthy
    Brian McCarthy almost 2 years

    How do you fix the Design-Time Error in the Windows Forms Designer?

    When I click on MyMainForm.cs[Design] page to bring up the WinForms i get the following error:

      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)  
    

    Here are my errors in 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
    

    Let me know if you need to see some of my code to help me out

    Here's the MainForm.Designer.cs file code:

    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;
        }
     }