例外:集合已修改;枚举操作可能无法在安装项目的形式执行关闭 [英] Exception : Collection was modified; enumeration operation may not execute on form Close in setup project

查看:2199
本文介绍了例外:集合已修改;枚举操作可能无法在安装项目的形式执行关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建建在C#4.0的窗口形式的应用程序的安装项目。我测试了在我的测试PC上安装具有安装在它VS 2010终极及其在其工作的罚款。



我稍后测试我安装到另一台机器不具有VS在它的应用程序。每次我试图关闭形式,它与此异常结束。唯一的例外是发生在某些形式并不适用于所有。我检查了代码,并且在它没有差别(this.close())。



在建设安装,我使用
.Net框架4客户端配置文件作为目标框架。
Microsoft.VisualBasic.PowerPacks.Vs设置中添加。
我不使用标签条,也没有试图关闭多种形态。



这是完整的错误
未处理的异常发生在您的应用程序。如果单击继续,应用程序将忽略此错误并尝试继续。如果你点击退出,应用程序将关闭rimmediately。



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

  **************异常文本************** 
System.InvalidOperationException:集合已修改;枚举操作可能无法执行。
在System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource资源)
在System.Collections.Generic.List`1.Enumerator.MoveNextRare()
在System.Collections.Generic.List`1.Enumerator .MoveNext()
在Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(布尔处置)在Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(布尔处置)在System.ComponentModel.Component

.Dispose()
在System.Windows.Forms.Control.Dispose(布尔处置)在System.ComponentModel.Component.Dispose()
。在System.Windows.Forms.Control.Dispose
(布尔处置)
在System.ComponentModel.Component.Dispose()
在System.Windows.Forms.Control.Dispose(布尔处置)在System.Windows.Forms.Form.Dispose
(布尔处置)
在ezyBizManager.Masters.frmUsers.Dispose(布尔处置)在System.ComponentModel.Component.Dispose()在System.Windows.Forms.Form.WmClose
(消息&
放大器;米)
在System.Windows.Forms.Form.WndProc(消息和M)
在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息和M)
在System.Windows .Forms.Control.ControlNativeWindow.WndProc(消息和M)
在System.Windows.Forms.NativeWindow.Callback(IntPtr的的HWND,味精的Int32,IntPtr的WPARAM,LPARAM的IntPtr)


**************加载的程序集**************
mscorlib程序
议会版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100)
基本代码:文件:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
--- -------------------------------------
ezyBizManager
议会版本:1.0 .0.0
Win32版本:1.0.0.0
基本代码:文件:/// C:/Program%20Files/Microsoft/COE/ezyBizManager.exe
--------- -------------------------------
System.Windows.Forms的
议会版本:4.0.0.0
Win32版本:4.0.30319.1通过内置:RTMRel
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0。 0__b77a5c561934e089 / System.Windows.Forms.dll的
------------------------------------- ---
System.Drawing中
议会版本:4.0.0.0
Win32版本:4.0.30319.1通过内置:RTMRel
基本代码:文件:/// C:/ Windows的/ Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
--------------------- -------------------
系统
议会版本:4.0.0.0
Win32版本:4.0.30319.1通过内置:RTMRel
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------- -----------------------------
将System.Data.Linq
议会版本:4.0.0.0
Win32版本:4.0.30319.1
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Data。 Linq.dll
----------------------------------------
System.Core程序
议会版本:4.0.0.0
Win32版本:4.0.30319.1通过内置:RTMRel
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/ GAC_MSIL / System.Core程序/ v4.0_4.0.0.0__b77a5c561934e089 / System.Core.dll
--------------------------- -------------
System.Configuration
议会版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100)
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
-------- --------------------------------
的System.Xml
议会版本:4.0.0.0
Win32版本:RTMRel
基本代码:文件:4​​.0.30319.1通过内置/// C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System .Xml.dll
----------------------------------------
System.Data这
议会版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100)
基本代码:文件:/// C:/ Windows的/微软。净/组装/ GAC_32 / System.Data这/ v4.0_4.0.0.0__b77a5c561934e089 / System.Data.dll中
----------------------- -----------------
System.Transactions的
议会版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100 )
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
---- ------------------------------------
的System.EnterpriseServices
议会版本: 4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100)
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4。 0_4.0.0.0__b03f5f7f11d50a3a / System.EnterpriseServices.dll
----------------------------------- -----
System.Xml.Linq的
议会版本:4.0.0.0
Win32版本:4.0.30319.1通过内置:RTMRel
基本代码:文件:/// C :/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
------------- ---------------------------
匿名运行DynamicMethods大会
大会版本:0.0.0.0
的Win32版本:4.0.30319.1(RTMRel.030319-0100)
基本代码:文件:/// C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
Microsoft.VisualBasic程序.PowerPacks.Vs
议会版本:10.0.0.0
Win32版本:10.0.20911.1
基本代码:文件:/// C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic.PowerPacks。 VS / 10.0.0.0__b03f5f7f11d50a3a / Microsoft.VisualBasic.PowerPacks.Vs.dll
------------------------------ ----------
Microsoft.VisualBasic程序
议会版本:10.0.0.0
Win32版本:10.0.30319.1通过内置:RTMRel
基本代码:文件:/ //C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
-------------- -------------------------- ************** JIT调试******** ******

要启用刚刚在实时(JIT)调试,.config文件文件中查找该
应用程序或计算机(Machine.config中)必须在System.Windows.Forms的部分设置
jitDebugging值。
上的应用程序也必须与调试
编译启用



例如:

 <结构> 
< System.Windows.Forms的jitDebugging =真/>
< /结构>



启用JIT调试后,任何未处理的异常
将被发送到注册的JIT调试器。在电脑上
,而不是由此对话框处理。



我用的图像关闭表单

 私人无效imgClose_Click(对象发件人,EventArgs五)
{
this.Close();
}


解决方案

我认为这是一个错误在的Dispose() ShapeCollection 的方法。如果我看这个方法例如使用.net反射,与Microsoft.VisualBasic.PowerPacks.Vs,版本= 9.0.0.0,它说的:

 的foreach(在this.m_Shapes形状的形状)
{
shape.Dispose();
}



如果我看看使用Microsoft.VisualBasic.PowerPacks.Vs这种方法,版本= 10.0.0.0,它说的:

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



显然,实施,版本之间的进化。后者不依赖一个枚举对象,因此不能失败,您显示错误。



有什么奇怪的,虽然是你的StackFrame似乎在暗示你关运行第10版,它不应该使用枚举?也许你需要VS 2010的更新?或者你也可以检查在你使用的Microsoft.VisualBasic.PowerPacks.Vs的Dispose执行



修改:一些挖掘后,您的应用程序确实运行在旧版本的VB壹佰的。升级到VS2010,SP1或从好的安装复制DLL。对于这个特定的处置错误,你至少需要10.0.30319.1。


I created a setup project of window form application built in C# 4.0. I tested the setup in my test PC which have Vs 2010 Ultimate installed in it and its working fine in it.

I later on to test the application I installed it another machine which does not have VS in it. Every time I try to close the form, it ends up with this exception. The exception is occurring in some forms not in all. I have checked the code and and there is no difference in it(this.close()).

While building the setup I am using .Net Framework 4 Client Profile as Target Framework. Microsoft.VisualBasic.PowerPacks.Vs is added in setup. My not using tab strip nor trying to close multiple form.

This is the complete error Unhandled exception has occurred in your application. If you click continue, the application will ignore this error and attempt to continue. If you click quit, the application will close rimmediately.

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** 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 **************

To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

[Edited:] I am using image to close the form.

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

解决方案

I think it's a bug in the Dispose() method of ShapeCollection. If I look at this method using for example .NET Reflector, with Microsoft.VisualBasic.PowerPacks.Vs, Version=9.0.0.0, it says this:

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

And if I look at this method using Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, it says this:

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

Clearly, the implementation has evolved between versions. The latter one doesn't rely on an Enumerator object and therefore cannot fail with the error you show.

What's strange though is your stackframe seems to imply you're running off version 10, which shouldn't use the enumerator?? Maybe you need a VS 2010 update? Or you can also check at the Dispose implementation on the Microsoft.VisualBasic.PowerPacks.Vs you're using.

EDIT: after some digging, your application indeed runs on an old version of the VB Powerpacks. Upgrade to VS2010, SP1 or copy the DLL from a good installation. For this specific Dispose bug, you need at least 10.0.30319.1.

这篇关于例外:集合已修改;枚举操作可能无法在安装项目的形式执行关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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