Tips for fixing form designer loading errors - MUST READ esp. MSFT

I don't have much time to write this all up but I'll give the basic gist and others can flush out. I'm too busy working to look into any solutions posted previously so I do apologize. But this problem was a pain in the arse for me and I wanted to share to help others who seem to have the same problem with inherited forms, designers, etc. So here goes:

To resolve any errors with forms loading up when you switch between source / designer, or errors after you do a build try the following:

General solution: SOMETHING in your code is causing errors that prevents the designer to load your form. Keep in mind the designer does execute some code when loading in the designer. The details of that I don't know.

Specific tips in order of importance (IMHO):
1) Get to know the attribute [DesignerSerializationVisiblity]. Why? In your form, you probably have a public property that is being serialized automatically by the designer. Many times, if you use the property browser, your custom property will be serialized as null and if you follow your code carefully, it'll probably cause your form to crash when its loaded in the designer. For any form, open up the designer.cs file, search for "null". If you see a bunch of null assignments to your custom properties, this is your most likely problem. This resolved nearly 95% of my forms not loading.

How to use:
[DesignerSerializationVisibility(something.Never)]
public MyUserControl MyUninitalizedControl {
get { ... }
set { ... }
}

Apply this to all form properties, user controls, derived controls, etc where necessary.

2) Get to know DesignMode property. In your onloads, etc, make sure you check if you're in design mode. If you are, you don't really need to load up database information during design time do you? (as an example). So, just do if (DesignMode) return;

3) Make sure your references are properly set. Don't set them to DLLs that can be used by other programs. This will also crash the designer.

Thats really all there is. Like I said, #1 solved 95% of my crashes, and #2 and #3 the other 5%.

Microsoft, please update so we can have better error message that help us fix problems. After getting this resolved, dev has been MUCH better.

[2250 byte] By [bensterdev] at [2007-12-22]