Really horrible experience

:( ok this really scared me today, well about 5 minutes ago. Maybe someone can explain to me what happened and how it could be avoided. Thanks in advance.

Everything was working fine in the Win Form application which i am making in C#, under VS 2003. Net. The form is visually inheriting from a base form. Neways , i set the "WindowState" property to maximise, and ran the application. It caused an error since there was some code being executed in the OnSizeChanged event of the base form. Then all of a sudden all the controls on the derived form had disapeared :(.

Luckily i had backed up the entire project few minutes ago so i copied and pasted the designer code back in. So can anyone please tell me why does the code from the InitializeComponent() function get removed when there is an error either in the base form or the main.

Thanks.


Answer this question

Really horrible experience

  • Ellanna

    Thank you guys, thats exactly what happened to me. I had about three projects within the same solution and i think one of the assembly did not get built, and the form was using a control from the invalid assembly, so whole thing just messed up and removed the controls from the main form.

    Here is a better explanation.

    " http://www.shawnburke.com/default.aspx document=183&userinterface=9
    Shawn Burke
    2/3/2005 1:41:48 PM
    Lance -- actually that's a different issue. That was (stupid and wrong) design decision we made back early in the development of VS 2002. I remember talking about it but just can't believe we did that, you're complaining to the right guy, so my apologies there. Basically what's happening is that you rebuild. The build of the control fails. The designer in the other project can't know that, it just sees that the assembly that has the control is no longer valid. It asks the project system for the WindowsControlLibrary.UserControl1 type, and the project system says "sorry, don't have it." So the designer (and this was the mistake; we should have just failed the load right then and there) shrugs its shoulders, and goes about its business. The net result is that the control is just plain gone, and if you make a change and save, it's gone for good. If you see this happen, you need to close the designer, answer "NO" when it asks to save changes, fix your build problems, then reopen it, and you should be okay. In VS 2005 we do the *right* thing and fail the load with a "could not find type 'WindowsControlLibrary.UserControl1'.
    "

  • mykes

    it is a common experience.  when VS tries to parse/deserialize the initializecomponent method and experiences an error, sometimes it will not be able to reproduce/recreate the error controls (i dunno about the others below it as declared in the InitializeComponent method, perhaps).  then if you changed anything on the form (like resizing it), the form designer will try to reserialize/regenerate code for the current form that he sees.  sometimes not saving the form changes will do, but knowing that changing any properties on the form or any property of any controls/components on the form will force the form designer to regenerate code will be handy.
  • erase_ego

    hmmm, i think i'm not good at explaining, :p
  • Terry Smith

    This might be the race condition problem that they recently discovered with C# [1]. Neno Loje has a blog entry [2] with links to several different knowledge base articles (some of which have have patches):

    I hope that helps.

    [1] http://www.shawnburke.com/default.aspx document=183&userinterface=9
    [2] http://dotnetjunkies.com/WebLog/nenoloje/archive/2004/06/18/16952.aspx

  • Really horrible experience