例外:收集被修改; 枚举操作可能无法在安装项目中的表单关闭上执行

我创建了一个使用C#4.0构建的窗体应用程序的安装项目。 我在我的测试PC中测试了安装程序,其中安装了Vs 2010 Ultimate并且工作正常。

我后来测试应用程序我安装了另一台没有VS的机器。 每次我尝试关闭表单时,都会以此exception结束。 例外情况以某种forms发生。 我检查了代码,并没有区别(this.close())。

在构建设置时,我使用.Net Framework 4 Client Profile作为目标框架。 在安装程序中添加了Microsoft.VisualBasic.PowerPacks.Vs。 我没有使用标签条,也没有尝试关闭多个表单。

这是完整的错误您的应用程序中发生了未处理的exception。 如果单击“继续”,应用程序将忽略此错误并尝试继续。 如果单击退出,应用程序将立即关闭。

有关调用实时(JIT)调试而不是此对话框的详细信息,请参阅此消息的结尾。

************** Exception Text ************** System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.List`1.Enumerator.MoveNextRare() at System.Collections.Generic.List`1.Enumerator.MoveNext() at Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean disposing) at Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.Windows.Forms.Form.Dispose(Boolean disposing) at ezyBizManager.Masters.frmUsers.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ************** Loaded Assemblies ************** mscorlib Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll ---------------------------------------- ezyBizManager Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/Program%20Files/Microsoft/COE/ezyBizManager.exe ---------------------------------------- System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System.Drawing Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Data.Linq Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Data.Linq.dll ---------------------------------------- System.Core Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll ---------------------------------------- System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Xml Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Data Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll ---------------------------------------- System.Transactions Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll ---------------------------------------- System.EnterpriseServices Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll ---------------------------------------- System.Xml.Linq Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll ---------------------------------------- Anonymously Hosted DynamicMethods Assembly Assembly Version: 0.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100) CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll ---------------------------------------- Microsoft.VisualBasic.PowerPacks.Vs Assembly Version: 10.0.0.0 Win32 Version: 10.0.20911.1 CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic.PowerPacks.Vs/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.PowerPacks.Vs.dll ---------------------------------------- Microsoft.VisualBasic Assembly Version: 10.0.0.0 Win32 Version: 10.0.30319.1 built by: RTMRel CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll ----------------------------------------************** JIT Debugging ************** 

要启用实时(JIT)调试,此应用程序或计算机(machine.config)的.config文件必须在system.windows.forms部分中设置jitDebugging值。 还必须在启用调试的情况下编译应用程序。

例如:

    

启用JIT调试时,任何未处理的exception都将发送到计算机上注册的JIT调试器,而不是由此对话框处理。

[编辑:]我正在使用图片来关闭表格。

 private void imgClose_Click(object sender, EventArgs e) { this.Close(); } 

我认为这是ShapeCollectionDispose()方法中的一个错误。 如果我使用例如.NET Reflector,使用Microsoft.VisualBasic.PowerPacks.Vs,Version = 9.0.0.0来查看此方法,它会说:

  foreach (Shape shape in this.m_Shapes) { shape.Dispose(); } 

如果我使用Microsoft.VisualBasic.PowerPacks.Vs,Version = 10.0.0.0查看此方法,它会说:

  for (int i = this.m_Shapes.Count - 1; i >= 0; i--) { this.m_Shapes[i].Dispose(); } 

显然,实现在版本之间发生了变化。 后者不依赖于Enumerator对象,因此不会因显示的错误而失败。

有什么奇怪的是你的堆栈框架似乎暗示你正在运行版本10,它不应该使用枚举器? 也许您需要VS 2010更新? 或者您也可以检查您正在使用的Microsoft.VisualBasic.PowerPacks.Vs上的Dispose实现。

编辑 :经过一些挖掘,您的应用程序确实运行在旧版本的VB Powerpacks上。 升级到VS2010,SP1或从良好的安装中复制DLL。 对于此特定的Dispose错误,您至少需要10.0.30319.1。

我有同样的pblm,尤其是LineShape ,在安装和搜索正确的PowerPacks软件包头痛之后,我用RichTextBox将它替换为balck和尺寸,它似乎很奇怪,但它对我来说比花费我的时间更好这个虫子!! (0_o)

我有同样的问题。 我对导致这个问题的原因感到困惑,并且已经逐步调试了一天左右。 在谷歌搜索并输入正确的描述之后,事实certificate问题在于表格上的线条形状 – 可能还有其他形状。 看到这里的链接,希望它能节省一些时间…你必须通过评论阅读,就像上面的post一样,它是线形的。

http://social.msdn.microsoft.com/Forums/en-US/cb89a159-c989-470f-b74f-df3f61b9dedd/systeminvalidoperationexception-when-closing-a-form?forum=vbpowerpacks

http://channel9.msdn.com/forums/TechOff/520076-VB-2010-Error-PowerPacks-Line-Shape-Dispose/