IDE Deletes my code

Hi, While using the Visual C# IDE to build a somewhat complex form (about 60-65 controls), I added a SplitContainer control to manage the layout of some of my controls.  After a couple of minutes of playing around with the properties of the SplitContainer, the IDE deleted all of my code from the form - ALL of it ! 

Fortunately, I was able to pull a copy off a backup drive.  I restarted the IDE and started making some more changes to the form, but the second time around I stayed far away from the SplitContainer control, and the IDE deleted all my code again !  Ive lost almost 2 days worth of work.

I dont know if this matters, but this was a form that was originally created in VS2003.

Has this happened to anyone else   Does anyone know what causes this

 



Answer this question

IDE Deletes my code

  • js123

    That's the well-known problem. The only bulletproof solution I found is to keep source code checked in some source control software and follow the following usage pattern:< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    1) Check out the form you want to edit

    2) Proceed with the changes

    3) See if it is OK

    4) Commit the changes into source control system.

    Later if you found that something went wrong (or I should say "Gone wild" =) - just

    compare the current source code with the code in the source controls system to find out  which lines of code were screwed up by Visual Studio and undo these changes.

    Of course it's recommended to keep source code in the "checked in" state most of the time to minimize damage and speed up the recovering process.

     



  • eLeeL

    Murpheux, great idea - that will save me a lot of time.  Thanks.
  • Dtag

    Here comes the “fun” part of programming - writing a program to move your forms. 



  • mcobrien

    Instead of creating a new form, I will suggest creating a new class file named in the convention of <formname>.designer.cs and mark the classes with partial. Copy the content in the VS generated code region into the new partial class definition.

    This I believe should make ur task faster



  • sleepy01011

    Peter,

    Thats exactly what I ended up doing - creating a new form and copying over and reattaching all the handlers.  The new IDE uses a separate file (from the handlers) for all the generated form code so I'm hoping this will prevent the problem from happening again.  What is annoying is that i will have to go through this exercise will all the forms i created in VS2003.

    Doung, Igor, thanks for your input - unfortunately, Ive been working with new IDE at home, where i dont have the luxury of a source control system, just nightly backups.


  • phillip toussaint

    That IDE behavior is unacceptable!

    < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

    I haven’t imported any forms from vs2003, nor have I had any form trouble (not that I do a lot of forms). Therefore, it seems to me that the idea of importing the form may not work so well. Since you lost a few hours already, it might be advisable to just redo the form and copy the old code into the new handlers.



  • frontierfox

    Good advise.

    I think you were also suggesting that the checkouts and checkins should be often. That way if your code starts misbehaving or the IDE does something to your code you don't like, you can simply undo the last five minutes of work...


  • IDE Deletes my code