C# 异常:集合被修改;枚举操作不能在安装项目中的窗体关闭时执行

C# 异常:集合被修改;枚举操作不能在安装项目中的窗体关闭时执行,c#,winforms,setup-deployment,C#,Winforms,Setup Deployment,我创建了一个在C#4.0中构建的窗口表单应用程序的安装项目。我在我的测试PC中测试了该设置,其中安装了Vs 2010 Ultimate,并且运行良好 稍后,为了测试该应用程序,我将其安装在另一台没有VS的机器上。每次我试图关闭表单时,它都会出现此异常。例外情况以某些形式出现,而不是全部。我已经检查了代码,没有任何区别(this.close()) 在构建我正在使用的设置时 .Net Framework 4客户端配置文件作为目标框架。 安装程序中添加了Microsoft.VisualBasic.Po

我创建了一个在C#4.0中构建的窗口表单应用程序的安装项目。我在我的测试PC中测试了该设置,其中安装了Vs 2010 Ultimate,并且运行良好

稍后,为了测试该应用程序,我将其安装在另一台没有VS的机器上。每次我试图关闭表单时,它都会出现此异常。例外情况以某些形式出现,而不是全部。我已经检查了代码,没有任何区别(this.close())

在构建我正在使用的设置时 .Net Framework 4客户端配置文件作为目标框架。 安装程序中添加了Microsoft.VisualBasic.PowerPacks.Vs。 我没有使用tab strip,也没有尝试关闭多个表单

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

有关调用的详细信息,请参阅此消息的结尾 即时(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)必须具有 在system.windows.forms节中设置的值。 应用程序还必须通过调试进行编译 启用

例如:

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

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

    foreach (Shape shape in this.m_Shapes)
    {
        shape.Dispose();
    }
    for (int i = this.m_Shapes.Count - 1; i >= 0; i--)
    {
        this.m_Shapes[i].Dispose();
    }
如果我使用Microsoft.VisualBasic.PowerPacks.Vs(版本=10.0.0.0)查看此方法,它会说:

    foreach (Shape shape in this.m_Shapes)
    {
        shape.Dispose();
    }
    for (int i = this.m_Shapes.Count - 1; i >= 0; i--)
    {
        this.m_Shapes[i].Dispose();
    }
显然,实现是在不同版本之间演变的。后者不依赖于枚举器对象,因此不会因显示的错误而失败

奇怪的是,你的stackframe似乎暗示你正在运行版本10,它不应该使用枚举器??也许你需要VS2010更新?或者,您也可以查看正在使用的Microsoft.VisualBasic.PowerPacks.Vs上的Dispose实现


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

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

    foreach (Shape shape in this.m_Shapes)
    {
        shape.Dispose();
    }
    for (int i = this.m_Shapes.Count - 1; i >= 0; i--)
    {
        this.m_Shapes[i].Dispose();
    }
如果我使用Microsoft.VisualBasic.PowerPacks.Vs(版本=10.0.0.0)查看此方法,它会说:

    foreach (Shape shape in this.m_Shapes)
    {
        shape.Dispose();
    }
    for (int i = this.m_Shapes.Count - 1; i >= 0; i--)
    {
        this.m_Shapes[i].Dispose();
    }
显然,实现是在不同版本之间演变的。后者不依赖于枚举器对象,因此不会因显示的错误而失败

奇怪的是,你的stackframe似乎暗示你正在运行版本10,它不应该使用枚举器??也许你需要VS2010更新?或者,您也可以查看正在使用的Microsoft.VisualBasic.PowerPacks.Vs上的Dispose实现


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

我有与相同的pblm,尤其是LineShape,在安装和搜索正确的PowerPacks软件包时遇到麻烦之后,我将其替换为RichTextBox,将backcolor调整为balck和大小,这看起来很奇怪,但对我来说,这比花时间和这个虫子在一起要好得多!!(0_o)

我使用了相同的pblm,尤其是LineShape,在安装和搜索正确的PowerPacks软件包时遇到麻烦后,我将其替换为RichTextBox,将其调整为黑色和大小,这看起来很奇怪,但对我来说比花时间处理这个bug要好!!(0_o)

我也有同样的问题。我一直很困惑是什么导致了这个问题,一天左右的时间里我一直在逐行调试。在谷歌搜索并输入正确的描述后,发现问题在于表单上的线条形状——以及可能的其他形状。看到这里的链接,希望它能为其他人节省一些时间。。。你必须阅读下面的评论,就像上面的帖子一样,都是线条


我也有同样的问题。我一直很困惑是什么导致了这个问题,一天左右的时间里我一直在逐行调试。在谷歌搜索并输入正确的描述后,发现问题在于表单上的线条形状——以及可能的其他形状。看到这里的链接,希望它能为其他人节省一些时间。。。你必须阅读下面的评论,就像上面的帖子一样,都是线条


您是否有可以在此处显示的Form.Closing或Form.Closing方法?仅仅是简单的异常并不是很有用。当您从foreach循环内的集合中删除项时,通常会引发该异常,例如,
foreach(集合中的var x){collection.remove(x);}
。也许形状的处理方法会做类似的事情吗?我现在有点困惑。我无法理解为什么相同的代码在另一种形式下工作良好。有什么我应该包括在我的安装项目。或者我可以运行任何更新。我已经安装了VS Framework 4.0您是否有可以在此处显示的Form.Closing或Form.Closing方法?仅仅是简单的异常并不是很有用。当您从foreach循环内的集合中删除项时,通常会引发该异常,例如,
foreach(集合中的var x){collection.remove(x);}
。也许形状的处理方法会做类似的事情吗?我现在有点困惑。我不明白为什么相同的代码可以工作