23

I'm using the Ribbon control located on CodePlex, and following the tutorial located here . Once I add the reference, and the proper code in the designer I get this error when I try to view the form:

Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown

And I cant figure out what I'm doing wrong. Anyone worked with this control and know how to resolve this issue?

PsychoCoder
  • 10,570
  • 12
  • 44
  • 60

6 Answers6

34

Interesting; I just ran into this same issue with one of my own forms; which is how I found your relevant and recent question.

Here's how I solved it:

  1. Open two instances of Visual Studio. Open the same project in both.
  2. In one instance, goto Debug->Exceptions and enable all the 'Thrown' options to stop at first chance exceptions. This will stop the debugger when the exception is generated.
  3. In the same instance, select Debug->Attach to Process, select devenv.exe.
  4. In the other instance, open the form to cause the exception
  5. With any luck the first instance should stop somewhere that yields a more relevant exception.

In my case it turned out to be something that I should have conditioned with:

if (!DesignMode)
{
  // Do something that should only happen at runtime
}

Don't forget turn turn off all those 'Thrown' options later.

pilotcam
  • 1,749
  • 14
  • 22
5

A workaround for me was:

  1. Right-click on the form and 'View Code'
  2. Keep the code loaded in the editor and then attempt to view the designer again.

This feels very glitchy and I cannot confirm whether it's a problem with my code (as I'm working on an entirely new codebase) or whether it's a VS2012 bug. If I find out, I will report back.

dev'd
  • 469
  • 1
  • 4
  • 12
  • For me it was kind of similar, but opening the code-behind wasn't enough. I had to open the designer code (yourformname.designer.cs) in the visual studio editor - and then the designer magically worked! Really weird. – Nicolas Jan 15 '21 at 11:25
4

Since the solution outlined by pilotcam didn't work for me, I took a different approach:

  1. Make a SVN commit for the file.
  2. Open the “*.designer.cs” file of the form that shows the error in source view.
  3. Remove larger blocks of form element declarations.
  4. Fix all compilation errors with ReSharper (i.e. ensure that nothing is red anymore on the side-indicator).
  5. Save the file. No need to compile.
  6. Open the Windows Forms Designer of the form.
  7. If the error still shows up, do a SVN revert to go back to the initial state.
  8. Repeat steps 2 to 7 until the error does not show up anymore.
  9. Now you’ve encircled the erroneous child control that causes the error.
  10. 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.

Community
  • 1
  • 1
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 1
    Even though the accepted answer is good, this one is very good too. Not really related to Visual Studio and the exception defined in the question but totally relevant in the context of "How to solve a problem" with tools. In my case, after a commit and then deleted a couple of lines where I thought the problem was, I finally found something interesting. I was able to isolated the error. I already knew your suggestion but I was not able to instinctively apply it without reading your answer and then remembering me how to think :D Thanks! – Samuel Feb 03 '16 at 18:59
2

I had the same issue and none of the above answers solved the problem.

At the end, emptying the "bin" folder and rebuild has worked for me.

Sleephead
  • 81
  • 5
0

Let me add two more cases when such exception can happen, along with when control tries to do something that is not allowed under design mode:

  1. When it's impossible to compile the user control.
  2. When designer code contains multiple similar (or identical) lines with initialization of same controls or properties, this can easily happen on merge.

All that cases produce same extremely meaningful error message, and in this particular two debugging of Visual Studio won't help, so I just ended up with bisecting my designer code.

Andriy K
  • 3,302
  • 31
  • 42
0
[ReadOnly(true)]

[Browsable(false)]

Above all properties worked for me

Paul Roub
  • 36,322
  • 27
  • 84
  • 93