System.ComponentModel.Design.ExceptionCollection

一笑奈何 提交于 2019-11-30 07:49:47

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


[ReadOnly(true)]

[Browsable(false)]

Above all properties worked for me



来源:https://stackoverflow.com/questions/9579544/system-componentmodel-design-exceptioncollection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!