Designer error


  • I recieve the following set of errors in the designer tab when I try and compile my program. I am new at using Windows Forms. I know you are not supposed to write code in the automatically generated code, but I don't know where else to put it. Could this be the problem?

    C++ CodeDOM parser error: Internal Error

    at Microsoft.VisualC.CppCodeParser.OnMethodPopulateStatements(Object sender, EventArgs e)
    at System.CodeDom.CodeMemberMethod.get_Statements()
    at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
    at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
    at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)

    Sunday, October 08, 2006 9:39 PM

All replies

  • you are not supposed to put code in the automatically generated part, like in the initialize component method.

    suppose, you put the following code in initialize component
    this->Text = count;
    you get an error window on the desinger similar to this though the error description might be different

    if you put the following code
    this->Text = "Text1";
    the code is valid and you see the form caption change to "Text1".

    Now suppose you add a button to the form by dragging from the toolbox, all the changes you made to the code are gone (like the statement above this->Text = "Text1").


    Tuesday, October 10, 2006 12:25 AM
  • Where am I supposed to put the code that I write?
    Wednesday, October 11, 2006 2:53 PM
  • anywhere outside, in your OnLoad override, eventhandlers, etc.
    Thursday, October 12, 2006 12:33 PM
  • Probably in the constructor
    Saturday, October 14, 2006 2:38 AM
  • When I write my own code in the constructor, and I want to use variables that I created in the Initialize component region, the compiler doesn't recognize the variable. error C2065 'variable' undeclared identifier
    Saturday, October 14, 2006 10:51 PM
  • You shouldn't be declaring variables in InitializeComponent; that's the whole point. You shouldn't be writing ANY code in InitializeComponent. If you are referencing class level variables, even if they are declared in the designer file, they are still accessible in the constructor.
    Saturday, October 14, 2006 11:17 PM
  • I have been having this problem as well, and in my search for a solution I found several threads like this where noone posed a solution. However, I potentially have one for you!!!

    I have found that when your code gets quite large the auto generated code gets really REALLY messy! It even puts duplicate lines in and inserts code in the wrong place causing errors!!!

    If moving the code to where it is supposed to be doesn't fix it, then there is another thing that the auto generated code forgets and is VERY picky about. Look for lines that are missing the "this->" parts! For example, it will start auto generating lines like the following:

    Button_MyButton =  (gcnew System::Windows::Forms::Button());

    However if you add the
    "this->" part like its supposed to do like the following:

    this->Button_MyButton =  (gcnew System::Windows::Forms::Button());

    then it stops complaining!

    When your code gets large and these errors start occuring, you have to be very careful with the auto generated code!

    I hope this helps people out there and saves them some time...

    Saturday, September 27, 2008 8:53 PM

  • However if you add the
    "this->" part like its supposed to do like the following:

    this->Button_MyButton =  (gcnew System::Windows::Forms::Button());

    then it stops complaining!
    This is a big big big bug.
    Buggy the VS is.
    Tuesday, August 25, 2009 9:52 AM
  • I just experienced the same problem also.

    Now I have removed all my code and put it somewhere else, now is there a way to restore the form?

    Saturday, July 27, 2013 5:49 AM