1

I'm getting the error: "Collection was modified; enumeration operation may not execute." thrown while a NameValueCollection is being modified(at least this is my assumption as to what is causing the error).

This is the code in which the collection is being modified, and all the research and other stackoverflow questions seem to only deal with foreach loops which is not the case in mine.

My question is: Where and why is this error occurring exactly, and what is a work-around for this error?

EDIT--- After opening and closing the form and exluding-reincluding the file, it opened and I could actually see the designer, but if I close VS2012 and reopen the Solution/Project, it goes back to this same error.

protected override void OpenEditCRMForm()
{
   NameValueCollection nvc = new NameValueCollection();
   nvc.Add("ModuleID", "1");
   nvc.Add("Key", this._crm.ID.ToString());
   nvc.Add("DisplayOnly", "false");
   nvc.Add("SaveChangesToDB", "true");
   ((IBaseDisplay)this).Load(nvc); //Just a custom interface overridden to load this Collection.

}

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.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Boolean allowPrivate, Assembly& assembly, String description)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
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.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String typeName)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) 
Adam
  • 2,422
  • 18
  • 29
  • 1
    That Generic.List make me think something in XAML. I have seen that. But only a comment. – paparazzo Aug 13 '14 at 13:35
  • Well, a comment is an idea which at least gives me something to go check out. It's just confusing because now I can see it again perfectly and no errors, but if I close MS2012, and reopen it, it gives the error. Like it just did now. – Adam Aug 13 '14 at 13:39
  • Perhaps you are doing something, what you shouldn't do when form designer is used. [Here](http://stackoverflow.com/q/2427381/1997232) and [here](http://stackoverflow.com/q/1166226/1997232) questions of how to detect it. – Sinatr Aug 13 '14 at 13:42
  • Can you test this with no zero XAML binding? That would tell you if it is XAML. You get names like that and a call stack coming from no where from XAML. But it could also be something other than XAML. – paparazzo Aug 13 '14 at 13:43
  • You should tag this WPF or WinForms. – paparazzo Aug 13 '14 at 13:45
  • Tagged. I'm not familiar with zero XAML binding @Blam – Adam Aug 13 '14 at 13:47
  • 1
    If it is WinForms you will not have XAML binding. You did not have it tagged. – paparazzo Aug 13 '14 at 13:58

0 Answers0