AAAARGH!!!!! visual studio just erased all my controls permanently

visual studio just erased all my controls.
some bug crept in to my code so the designer couldnt design the form. normally this results in the designer giving an error - but not this time. 

it rather cleverly decided to erase all the design i had made, and of course, because this didnt actually come to light until i hit COMPILE this has now been saved over the code i could have otherwise debugged

the initializecomponent() function now contains all of the declarations but not a single definition. 

this is a tab-based application with so far over 400 controls in it. there is months of design work in this, and now its just been erased without ANY suggestion by Visual Studio as to what is going on. this is a serious bug if ever i have seen one !!!

my most recent backup is over 2 weeks old (and quite useless). yes i know i should have backed up more recently, but quite frankly, you dont expect software costing £850 to erase months worth of work AND save it over what you could have recovered from. quite frankly, i am extremely disappointed

furthermore, MSVC doesnt automatically save backups of files when they are overwritten (unlike other examples of rather excellent software that i use) so i have nothing immediate to go back to. almost every other application i use has an auto-backup feature that appends .bak to filenames as they are overwritten. a single line of .NET code is all that is required to do this - why is it not implemented microsoft

i should also mention, this is NOT the first time this has happened - 3 times in the past this has happened, but so far on small forms with 10 or so controls on, so i didnt care or feel the need to mention it here - but this has set me back by at least a full days work, and im rapidly approaching my deadline.

thanks a bunch microsoft




Answer this question

AAAARGH!!!!! visual studio just erased all my controls permanently

  • Mullvaden

    i should add at this point, one thing i did see when the error occurred

    i was looking at the designer at the time, so the build output (before compiling) shows a list of errors in the designer process

    there was several hundred of them, all saying something along the lines of 'reference not made to an instance of an object'

    of course, by the time i actually noticed them, i had already hit compile and it was too late

    boy am i depressed...

  • creativeluf

    right i am getting very annoyed now!

    i'm unable to add any controls to this form now. im back at a blank form. the code near the designer function had some of my own private declarations in, so ive removed them for now, to keep it all nice and simple

    it now looks like this (immediately below the constructor)

    -----------------------------------------------------------------------

    protected: 
    void Dispose(Boolean disposing)
    {
    if (disposing && components)
    {
    components->Dispose();
    }
    __super::Dispose(disposing);
    }


    private: 
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::IContainer *  components;

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {

    }

    -----------------------------------------------------------------------

    ive created a new blank form and noticed that the designer function is incorrect. so ive pasted into it, from the new form, to look like this

    void InitializeComponent(void)
    {
    this->components = new System::ComponentModel::Container();
    this->Size = System::Drawing::Size(300,300);
    this->Text = S"x";
    }

    which is exactly what is shown in my new blank form. all of this section of code now looks identical to my new blank form - the definitions are in the right place, the functions are all in the right places, and the comments are also in the right places

    so far so good...

    i switch to the designer, which now has the text 'X' in the title bar. as expected. i hit save, and it saves. all good.

    so now i add a button to the form. just straight off the toolbar, a basic normal standard button. without any further ado, i hit save again

    i now have 2 errors - ' Object reference not set to an instance of an object'
    both usefully shown as being on line 0

    checking the designer function, i see it now looks like this

    void InitializeComponent(void)
    {
    this->button1 = new System::Windows::Forms::Button();
    this->SuspendLayout();
    this->ResumeLayout(false);
    }

    so its put in the button definition but not any of the code that places it on the form. looking at this same code in my new form shows me this

    void InitializeComponent(void)
    {
    this->button1 = new System::Windows::Forms::Button();
    this->SuspendLayout();
    // 
    // button1
    // 
    this->button1->Location = System::Drawing::Point(96, 120);
    this->button1->Name = S"button1";
    this->button1->TabIndex = 0;
    this->button1->Text = S"button1";
    // 
    // x
    // 
    this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
    this->ClientSize = System::Drawing::Size(292, 266);
    this->Controls->Add(this->button1);
    this->Name = S"x";
    this->Text = S"x";
    this->ResumeLayout(false);
    }

    so clearly there is a lot going wrong here!

    i return to the designer and delete the button. returning to the code shows me that the initializecomponent() is now completely empty, not a single line of code in there

    to be honest i have absolutely no idea what is going on. but i do know this - i'm a good week behind on this project, it looks to me now like i will have to start the whole thing from scratch, as a fresh project, then copy/paste all of my functions into it. not pretty.

    whats most annoying is that i am here to muddle through this by myself. the software is offering me no clues whatsoever as to what is going on, and im wasting time and money trying to figure it out


  • Andrey33

    it gets better!

    im (again) trying to rebuild things

    im adding controls to my now blank form. 

    and they arent appearing in the code! fantastic!

    for every control i am now getting one of those errors in the build output (which, as it happens, appears when i hit save)

    'Object reference not set to an instance of an object' is the error, one for each and every control i have put back into the designer

    and while their definitions and declarations are appearing in the code, the sections that set the properties and place them on the form are simply not there

    so what the hell am i supposed to do now  as soon as i hit compile, this will all get erased from the designer...



  • Nickthegreek

    i dont see how VSS can help. ive already been thinking about the macro thing tho

  • HidekiAI1

    If you're using C# or Managed Extensions for C++:

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>

    If you're using VB.NET:

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.

    If you're using J#:

        /**
        * Required method for Designer support - do not modify
        * the contents of this method with the code editor.
        */
     
    No matter which .NET language you use with Visual Studio, changing the Form Designer code is a big risk.  The only time I ever edit this code myself is to add or remove events in C#, and I am quite sure that there is a way to do this with the IDE besides double-clicking on a control.

  • perfectfalcon

    <i>> The only time I ever edit this code myself is to add or remove events in C#, and I am quite sure that there is a way to do this with the IDE besides double-clicking on a control. </i>

    You can add/remove events with the C# forms designer very easy. In the properties window, you have an extra button in the propertygrid (the flash). It shows all the events of the selected control and you can double-click an event to create a new event handler, select one from the list of already available event handlers or just delete it by pressing Del. This feature is not available in VB.NET for some reason...

  • DagDoug

    I've encountered this bug as well.  This is something Microsoft should fix.  However, I would recommend you start using source control or keeping up-to-date backups so you don't lose so much work.  


  • Rey_S2006

    Delete the whole entire Form and start completley over again.  Leave no trace of code from the old class.
  • mattaz

    ok ive got myself a 3rd party source control - CVS. so far so good.

    ive started a fresh form to re-create this app in. so far NOT so good - VS is deleting control definitions at will. at least its leaving the declarations and all the important code that lives in the designer function - but the definition lines above this keep vanishing

    every 2 or 3 times i compile, there will be some lines missing from the definitions. at least the rest of the code is intact - so its only a couple of lines i have to replace.

    BUT

    this shouldnt be happening at all. i am not impressed. and if this continues, then development will turn into a nightmare very quickly indeed.



  • hpdvs2

    > suerly i cannot be expected to copy/paste my entire work folder to a backup 
    > location every single time i compile  this would mean shutting down VS in 
    > order to do so, because it locks certain files and so they cannot be copied 
    > without shutting down 

    Use a source control system such as VSS.  Or create a macro that backs up your source code with every compile. 

  • TimothyB

    let me make one thing clear - i never once changed the code within the initializecomponent() function. NEVER. 

    this bug, whatever it was, would have been in the code above this, or in an included file. i have no idea what the bug was as i didnt get a chance to debug it. all i know is that after this bug crept in, the contents of my form were erased

    for what its worth, im now on my 2nd day of rebuilding it, and im approaching the half-way point


  • DDressel1

    Why are you creating a form with several thousand lines of code and 400 controls on it   Break it up into small pieces.  On my last project, we had several complicated forms with lots of controls on them.  So, what we did was to*space
    space*each form down into seperate custom controls.  For example, let's say we have a customer form with the following tab pages:

    Summary
    Name
    E-mail addresses
    Address
    Phone numbers
    POs
    Invoices

    The contents of each tab page was broken out into its own custom control.  Each tab page = custom control.  That way, in the worst case scenerio, if VS.NET deleted the controls, it would only happen on one tab page, not the entire form.  (Actually, for us VS.NET deleted the custom control from the form so to fix it you only had to add one control back to the form.)

  • rokohl

    RIGHT

    ITS JUST HAPPENED AGAIN

    i was editing code in a function several thousand lines below the InitializeComponent() 
    simply trying to get my data to show correctly in a treeview. i was not playing with the designer function, or doing anything whatsoever that could be 'dangerous' - i was doing the common task of perfecting my code...

    i hit compile
    i hit run

    an exception appears immediately so i go into debug
    it complains that a certain column doesnt exist in my datatable

    WHY

    BECAUSE VISUAL STUDIO HAS DECIDED TO ERASE IT ALL

    im already almost 3 whole days behind on this project - and now im going to be a whole week behind

    BECAUSE OF AN AWFUL BUG OF HUGE IMPORTANCE THAT HAS BEEN OVERLOOKED

    my company paid £850 for this software - thats not a small figure.
    for this amount of money i would expect any bugs of any size or importance to have been removed by now. 

    but for something of this magnitude it is disgusting

    i am completely and totally appalled at the quality of this software. it is absurd that it can have an effect of this scale so easily - and there is no way i can easily back everything up when i compile, so there is little i can do. 

    suerly i cannot be expected to copy/paste my entire work folder to a backup location every single time i compile  this would mean shutting down VS in order to do so, because it locks certain files and so they cannot be copied without shutting down

    very often, the changes made in between compiles amount to very little - adjusting a single line of code is quite common. surely i cannot be expected, every time i add a close-bracket that was missed, to shut down VS, copy/paste the whole folder, reboot VS and compile

    sorry but my employers dont pay me to waste time. they pay me to write software quickly. and now they are asking questions as to why this is happening, and i cannot give them a satisfying answer.

    potentially, my position of employment could be on the line because of this. i cannot stress enough how badly this is affecting my work life.

    MICROSOFT

    SORT IT OUT


  • Mike Weerasinghe

    Using a source control system like VSS lets you create backups of your files whenever you want and without exiting VS.NET.
  • AAAARGH!!!!! visual studio just erased all my controls permanently