Since converting our company inhouse winforms application from a VS2008 to VS2012 project I have problems using the winforms designer.
Sometimes the designer falls into an error state giving the following error message:
"Collection was modified; enumeration operation may not execute." with the call stack saying:
Instances of this error (1)
1. Hide Call Stack
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblySpecFound(List`1 assemblies, String assemblyFullName)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AddDependencies(Assembly a, String fileName)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchByShortName(String partialName, String fullName, AssemblyEntry[] entries, Assembly& assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, Boolean fastSearch)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName, String typeName, Boolean ignoreCase, Assembly& assembly, ReferenceType refType)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetAssembly(AssemblyName name, Boolean throwOnError)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetAssembly(AssemblyName name)
at Microsoft.VisualStudio.Design.VSDynamicTypeService.OnAssemblyResolve(Object sender, ResolveEventArgs e)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
It seems that the designer is trying to change the list of referenced assemblies maybe because of some invalid assemblies. While trying to solve the issue I figured out that changing the "Enable ClickOnce Security" option under Project->Properties->Security can bring the designer back to work. BUT if the option is turned on and I get the designer error turning it off and rebuild all can solve the problem from time to time and VICE VERSA!!!! ... That's why I'm a little lost right now.
I had the same problem, which drove me crazy all day. The cause (apart from the Visual Studio bug itself of course) was that my project was missing an assembly reference. To be precise, it referenced two assemblies A and B, where A itself also referenced B - but in a different version from the one I used. I should have referenced the same version of B that A referenced.
What it boils down to is: My assembly references weren't quite right. They were right enough for the code to compile and run just fine, but wrong enough for the WinForms designer to crash.
To find the problem, I started a second VS instance and attached its debugger to the first one that had my solution loaded (Debug | Attach to Process). Then in Debug | Exceptions, I activated breaking on thown Common Language Runtime Exceptions. Now, in my first VS instance, I double-clicked the form to open it.
I got multiple exceptions in a row, most of which had nothing to do with my code. But one of them was a FileLoadException stating: "Could not load file or assembly 'XXX, Version=3.7.0.25089, ..." So I added a reference to the correct version of the assembly. (And by correct, I mean down to the last digit - the WinForms designer is terribly pedantic when it comes to assembly versions.) And next thing I know, the form opens like a charm!
It seems to be a generell Visual Studio 2012 Bug.
Here is the offical mail I got from Microsoft
Greetings from Microsoft Connect!
This notification was generated for feedback item: VS2012 WinForms Designer doesn't work anymore -Error: Collection was modified; enumeration operation may not execute.which you submitted at theMicrosoft Connect site.
Thank you for your feedback. This bug is a duplicate of the one reported here: http://connect.microsoft.com/VisualStudio/feedback/details/781193/form-designer-error-collection-was-modified-enumeration-operation-may-not-executethere Please monitor that issue (781193) for further updates. There are no workarounds available, but we are fixing this issue in the next release of Visual Studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With