Designer Can't load Form

Please can someone from Microsoft explain why often the Visual Studio Designer can't load a form. In short the red banner that the designer displays instead of a form's design.

There was a thread on this subject 'designer can't load form. Where is 'more information'?', but no conclusion was reached as far as I can see.

In my most recent problem with this, rebuilding had no effect, and eventually it was fixed by simply closing all documents, closing Visual Studio, and re-opening the project - no changes were made! However more often the affected form is not recovereable at all.

This is obviously a major issue in Visual Studio and seems to occur randomly. Certainly no code changes are required to break a form (or to fix it in the most recent instance).

I have lost entire forms shortly after completing their development which might have taken months. There is no suggestion of what might cause the problem. The list of 'error messages' is just an internal call stack which gives no clue as to what the error is.

While it is possible to recover the code from the source file, recreating the visual design and re-wiring up the events is time consuming and invalidates the test phase which also takes weeks. More importantly it should not have to be done at all if no changes have been made to the form. As far as I can tell, this is a bug in Visual Studio which occasionally corrupts the form design during saving.

I think it's time Microsoft provides a concise explaination why they sometimes display this message and provide an official recovery process to recover the affected forms.

I also think the next release of Visual Studio should notify the developer of the specific reason it cannot load a form rather than the generic error message currently used. This would allow the developer to simply fix the problem rather than recreating the form. This does not seem unreasonable to me, and I'm a little surprised this information is currently withheld.

[2095 byte] By [MatthewLangley] at [2007-12-28]
# 1

Matthew,

There are a number of reasons why a designer might not load. If you understand the issues, you *might* be able to get it working again.

Check for these things:

1) You might be calling data model specific code from you constructor. Since the designer calls the constructor, any code in your constructor must be designer friendly. Instead, use the OnLoad function or Load event and check for DesignMode before doing any application specific code.

2) You might have public custom properties in your control. If you do, and the properties are not designer friendly, make sure you use the Browsable(false) and DesignerSerializationAttribute(Hidden) attributes.

If you want to get "more information", you can try running VisualStudio from VisualStudio (by setting a project properties to launch an external application). When the designer fails in the launched VisualStudio, you will get a nice and pretty stack trace describing the problem.

Hopefully that'll help.

-Grg

GregShaffer at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 2

Thanks Greg,

These are very good suggestions and I will use 'em.

Especially the debugging of Visual Studio to find the actual error. (This is not a technique that I was previously aware of, and you can spend weeks staring at the constructor code and not be able to spot a potential problem without knowing the actual run-time error.)

In my recent example the constructor had not changed (indeed I fixed the problem by cutting and pasting all controls and code to a new form - hence my belief that VS had somehow corrupted the old source files). I can only assume that some data that the constructor of the form uses must have changed creating a previously unknown error in the constructor - not sure how cutting and pasting the code and controls to a new form fixed this.

I still think the next release of Visual Studio should catch any errors and report them to the user (without the need for debugging Visual Studio itself) rather than hiding the error and just saying the form is unloadable.

Matt.

MatthewLangley at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 3

Hi Matthew,

We have actually just posted a video walking through why this screen appears, including a proposed new design for the Design-Time Error List:

http://blogs.msdn.com/brada/archive/2007/01/16/what-is-next-for-winforms-wsod-in-orcas.aspx

Head over, watch the video, and give us some feedback on how to make the experience better!

Thanks,

Scott Morrison

Program Manager

Windows Forms Team

Scott_Morrison at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Designer...