Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Tuesday, February 22

Controls disappear in designer

This happened to me already on a few occasions (in Visual Studio 2002 and 2003) and it now really starts bugging me! I have taken a closer look at it and I did some research about it so that I'm able to prevent this in the future (hopefully). I lost already quite some time to redesign my forms and I do not want to be in the same s*** again or at least I know what to do to recover quickly ...

Let me explain what exactly happens ... I'm designing a Windows Form with a tabControl and on each tabPage there's a userControl. When I make changes to this Windows Form, once in a while some of my userControls are removed from the tabPages without any specific reason. It appears - after comparing source files in source-control - that Visual Studio is removing lines of code in the InitializeComponent() method [Component Designer generated code] of the constructor in the form. The solution is still buildable because the private variables of my usercontrols are still declared, but the problem is that the instantiation doesn't occur anymore during the initialization and the usercontrol is therefore not visible anymore in the designer and it results in run-time errors : object reference not set to an instance of an object. Luckily we're using a source-control system and I'm able to rollback to a working version but this is REALLY annoying me because a lot of development-time is wasted. I can imagine that even more time is wasted (read this post in the Windows Forms Forum from a developer who really got frustrated) when you're not using a source-control system or when a lot of plain controls are removed from your form. In my case, I only had to reposition my usercontrols on the desired tabpages after having cleaned the declarations of the troubled usercontrols. I strongly advise you to do regularly check-ins when working with the designer. It's also known that changing code in the auto-generated code section often will give you troubles, but I'm sure that this didn't create the bug in my form because I really wasn't playing around with that code-section.

Finding a reliable reproduction for this bug is almost impossible because it seems to happen at any given moment. I hope that Microsoft has already resolved this designer-bug in the next release of Visual Studio. A patch for Visual Studio 2003 will also be appreciated by many developers I assume.

I've also googled the bug and a colleague gave me a good link with interesting tips when working with the designer. Here's an overview :
  • Check-in your design-forms as often as you can so that you're able to perform a rollback when needed.
  • Close all designer-windows before starting a build, before switching to release/debug and before closing your solution.
  • Build your entire solution before opening a designer-window.
  • Remove the references to the assemblies that contain the controls that vanished, and add them back again.
While I was finishing my post to publish it, I came across this post from Shawn Burke. It seems that the issue will be gone in Visual Studio 2005! Definitely one version too late for me and hotfixing it in VS 2003 looks very risky ;-(

1 Comments:

  • At 4:22 PM, Anonymous Anonymous said…

    Same problem here... very annoying!

     

Post a Comment

<< Home