Recently I got an error message
---------------------------
Microsoft Visual Studio
---------------------------
Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown.
---------------------------
OK
---------------------------
when trying to edit a form in the Windows Forms Designer of Visual Studio .NET 2010. Searching Google for this error brought up some results but didn’t help me.
There was one hint that stated:
Sometimes I get the message „Exception of type ‚System.ComponentModel.Design.ExceptionCollection‘ was thrown“ When trying to open a Form in designer view.
The real problem of the „ExceptionCollection“ being thrown is that when there is a WSOD (White Screen of Darn) indicating a designer load issue, the designer gets unloaded. These get caught by the unload method and get displayed in the dialog box you see.
So, to fix this you should:
- Attach a visual studio debugger to VS. Turn on exception catching when first thrown (in the Debug|Exceptions menu).
- Open the designer with the debugger attached
- Determine what component is throwing the exception.
This was actually a copy from a Microsoft Connect bug report. I tried this, but the error message still popped up and the debugger never stopped at this message (although it stopped at other native errors).
Steps to solve
Since all this didn’t help, I did another approach that was finally successfully:
- Make a SVN commit for the file.
- Open the „*.designer.cs“ file of the form that shows the error in source view.
- Remove larger blocks of form element declarations.
- Fix all compilation errors with ReSharper (i.e. ensure that nothing is red anymore on the side-indicator).
- Save the file. No need to compile.
- Open the Windows Forms Designer of the form.
- If the error still shows up, do a SVN revert to go back to the initial state.
- Repeat steps 2 to 7 until the error does not show up anymore.
- Now you’ve encircled the erroneous child control that causes the error.
- Repeat steps 2 to 7 with a smaller amount of controls you remove, until you have only one control left.
In my case it was a user control inside a group control inside a tab control, so I first identified the tab control, then the group control and then the user control.
You could isolate the user control inside a new form to further investigate. In my case it was rather easy; I put checks for design mode around most of the functions inside my control to ensure the code only gets executed if the control is not in design mode.
This fixed my error.
See also: