Solved

Error being thrown in Win 8.1 but not Win 7 nor Vistsa. Appears to be form closing event.

Posted on 2014-10-06
12
364 Views
Last Modified: 2014-10-06
I have an app that is causing errors to be thrown on a couple of forms during the closing event. Th error is only showing up on Windows 8.1. Win 7 and Vista are not throwing the error.

Is this bad code where the older OS's were forgiving me or is it something else? The APP is in VB.net 2008. I can click continue on the error and the APP keeps running as intended.

Unfortunately my debugging is limited because I do not have Win 8.1.

    Private Sub Form7_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim frm As Form
        For Each frm In Me.MdiParent.MdiChildren
            If TypeOf frm Is Form2 Or TypeOf frm Is Form3 Or TypeOf frm Is Form4 Or TypeOf frm Is Form5 Or TypeOf frm Is Form6 Or TypeOf frm Is Form8 Or TypeOf frm Is Form9 Or TypeOf frm Is Form10 Or TypeOf frm Is Form11 Or TypeOf frm Is Form12 Or TypeOf frm Is Form13 Or TypeOf frm Is Form14 Or TypeOf frm Is Form15 Or TypeOf frm Is Form16 Or TypeOf frm Is Form17 Or TypeOf frm Is Form18 Or TypeOf frm Is Form19 Or TypeOf frm Is Form20 Or TypeOf frm Is Form21 Or TypeOf frm Is Form22 Or TypeOf frm Is Form23 Or TypeOf frm Is Form24 Or TypeOf frm Is Form25 Or TypeOf frm Is Form26 Or TypeOf frm Is Form27 Or TypeOf frm Is Form28 Then
                frm.Close()
            End If
        Next
    End Sub

Open in new window

0
Comment
Question by:PBLack
  • 6
  • 4
  • 2
12 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365067
Can you post error raised?
0
 
LVL 40
ID: 40365071
If we do not know what the error is, we cannot answer.

Also, is it always happening on the same forms. Calling Close on these forms will also trigger the FormClosing error on them, so it might be where you have a problem. The code that you are showing should usually not give problems by itself.
0
 

Author Comment

by:PBLack
ID: 40365089
Hold on I will get them to send me a screen shot
0
 

Author Comment

by:PBLack
ID: 40365102
Message from error box

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 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.Windows.Forms.TabControl.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)
   at comstock_Compiler.Form7.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: 2.0.0.0
    Win32 Version: 2.0.50727.8009 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
comstock Compiler
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files%20(x86)/comstock/comstock%20Compiler/comstock%20Compiler.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.7905 (win9rel.050727-7900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8008 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8009 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8003 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
OpenNETCF.Desktop.Communication
    Assembly Version: 2.9.2244.24857
    Win32 Version: 2.9.2244.24857
    CodeBase: file:///C:/Program%20Files%20(x86)/comstock/comstock%20Compiler/OpenNETCF.Desktop.Communication.DLL
----------------------------------------
System.Data.SqlServerCe
    Assembly Version: 3.5.1.0
    Win32 Version: 3.5.8080.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Data.SqlServerCe/3.5.1.0__89845dcd8080cc91/System.Data.SqlServerCe.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.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
----------------------------------------

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

Open in new window


Screen shot
error.JPG
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40365108
And you say it worked before? I focused on that statement and did not look further. But with the error message, it becomes evident.

You cannot remove elements from a collection when you loop with a for each. You have to do it in reverse with the "standard" for, replacing each instance of frm by Me.MdiParent.MdiChildren(x):

For x As Integer = Me.MdiParent.MdiChildren.Count-1 to 0 Step -1
     If TypeOf Me.MdiParent.MdiChildren(x) Is Form2 ... Then
          Me.MdiParent.MdiChildren(x).Close()
     End If
Next
0
 

Author Comment

by:PBLack
ID: 40365113
Yes it works 100% of the time on Vista and Win 7 installs. Today was the first time it was installed on Win 8.1. I will make the change you suggested and issue a fix, just in case.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:PBLack
ID: 40365122
I closed the question too soon.

Me.MdiParent.MdiChildren.Count -  Error: 'Count' is not a member of 'System.Array'
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365125
Try changing the For to :

For x = 0 To (Me.MdiChildren.Length) - 1
0
 

Author Comment

by:PBLack
ID: 40365145
@samo4fun - thank you
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365148
Just thank you? Kidding ;)   glad to help ...
0
 

Author Comment

by:PBLack
ID: 40365199
Well I wish I could give you some points but stupid me closed it.
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365201
No biggie...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now