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 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/
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)