Exception : Collection was modified; enumeration operation may not execute on form Close in setup project

折月煮酒 提交于 2019-12-01 14:23:06

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.

I had the same pblm with, especially with LineShape, after headache with installing and searching for right PowerPacks package, I replaced it with RichTextBox by adjusting backcolor to balck and the size, it seems weird but it's quite better for me than spending my time with this bug !! (0_o)

I had the same problem. I've been so confused as to what was causing the issue and have been stepping through debugging line by line for a day or so. After Google searching and typing in the right description, it turns out the issue is with line shapes on a form - and likely other shapes. See the links here, hope it saves somebody else some time... you have to read down through the comments, by like the above post it's with line shapes.

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!