我如何解决错误'集合被修改;枚举操作可能不会执行。在Visual Studio 2012中 [英] How Do I Resolved Error 'Collection Was Modified; Enumeration Operation May Not Execute.' In Visual Studio 2012

查看:117
本文介绍了我如何解决错误'集合被修改;枚举操作可能不会执行。在Visual Studio 2012中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows窗体应用程序中打开设计器时出现此错误.. !!



错误堆栈跟踪在这里..



at HDipak.Global.SetControlBackColor(Control _cltr)

at HDipak.frmMaster.frmMaster_Load(Object sender,EventArgs e)in d:\Development-SGI \ HDipak \\ \\ HDipak \ Bulk \frmMaster.cs:第628行

在System.Windows.Forms.Form.OnLoad(EventArgs e)

在System.Windows.Forms。 Form.OnCreateControl()

在System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

在System.Windows.Forms.Control.CreateControl()

在System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)

在System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)

at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)

在System.Windows.Forms.Control.SetVisibleCore(布尔值)

在System.Windows.Forms。 Form.SetVisibleCore(布尔值)

在System.Windows.Forms.Control.set_Visible(布尔值)

在System.Windows.Forms.Design.DesignerFrame.Initialize(控制视图)

在系统.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent组件)

在System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent组件)

在System.ComponentModel .Design.DesignerHost.AddToContainerPostProcess(IComponent的组件,字符串名称,的IContainer containerToAddTo)在System.ComponentModel.Design.DesignerHost.PerformAdd

(IComponent的组件,字符串名称)

。在System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(类型组件类型,字符串名称)在System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance

(类型类型,ICollection的参数,String name,Boolean addToContainer)

在System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.Componen tModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(类型类型,ICollection的参数,字符串名称,布尔addToContainer)

在System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager经理,CodeTypeDeclaration声明)<登记/>
。在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager经理)

。在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)<在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(的Int32 fReload)

BR />


请帮我找到解决方案.. !!



提前谢谢: - )

解决方案

会员11254922写道:

请帮助我找到解决方案.. !!



这个问题的描述是不可能的!



调试程序以找出发生错误的地方。



请看类似的问题:

如何处理此错误:收集已修改;枚举操作可能无法执行。 [ ^ ]

收集被修改;枚举操作可能无法执行。 [ ^ ]

收集被修改;枚举操作可能无法执行。 [ ^ ]

http://stackoverflow.com/questions/2024179/c-sharp-collection-was-modified-enumeration-operation-may-not-execute [ ^ ]

http://stackoverflow.com/questions/604831 / collection-was-modified-enumeration-operation-may-not-execution [ ^ ]

我们无法告诉你该做什么:我们可以看到你的代码。

但是很可能你使用 foreach 循环并修改您正在循环的集合中的内容(添加或删除元素):

 List< string> ; myList = GetStrings(); 
foreach string s in myList)
{
...
myList.Remove(s);
...
} < / string >

这是不允许的:您在枚举时无法修改集合。

检查SetControlBackColor函数中的代码,看看你有什么:我们不能!


this error come up while opening designer in windows form application..!!

Error Stack Trace is Here..

at HDipak.Global.SetControlBackColor(Control _cltr)
at HDipak.frmMaster.frmMaster_Load(Object sender, EventArgs e) in d:\Development-SGI\HDipak\HDipak\Bulk\frmMaster.cs:line 628
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Design.DesignerFrame.Initialize(Control view)
at System.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent component)
at System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent component)
at System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent component, String name, IContainer containerToAddTo)
at System.ComponentModel.Design.DesignerHost.PerformAdd(IComponent component, String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
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)

Please Help Me to Find the solution..!!

Thanks in Advance :-)

解决方案

Member 11254922 wrote:

Please Help Me to Find the solution..!!


It's impossible with this piece of issue's description!

Debug the program to find out the place where an error occurs.

Please, see similar questions:
How to handle this error: Collection was modified; enumeration operation may not execute.[^]
Collection was modified; enumeration operation may not execute.[^]
Collection was modified; enumeration operation might not execute.[^]
http://stackoverflow.com/questions/2024179/c-sharp-collection-was-modified-enumeration-operation-may-not-execute[^]
http://stackoverflow.com/questions/604831/collection-was-modified-enumeration-operation-may-not-execute[^]


We can't tell you from that what to do: we can;t see your code.
But the chances are that you are using a foreach loop and modifying the content (adding, or removing an element) from the collection you are looping on:

List<string> myList = GetStrings();
foreach(string s in myList)
   {
   ...
   myList.Remove(s);
   ...
   }</string>

This is not allowed: you cannot modify a collection while it is being enumerated.
Check your code in the SetControlBackColor function, and see what you have: we can't!


这篇关于我如何解决错误'集合被修改;枚举操作可能不会执行。在Visual Studio 2012中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆