Thursday, August 29, 2019

Weird .Net error Collection was modified; enumeration operation may not execute.

I got this error when closing a form, and it isn't pointing to a certain line of code it just happens.
The code has been running without problem for more than 5 year. But then I had to change from Win7 VS2013 to Win10 VS2017, BAM! I got this error.

System.InvalidOperationException
  HResult=0x80131509
  Message=Collection was modified; enumeration operation may not execute.
  Source=mscorlib
  StackTrace:
   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.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
   at MN_Bargraph.MN_BarGraph.Dispose(Boolean disposing) in C:\MN_Bargraph\UserControl1.Designer.vb:line 13

It said something about .Designer.vb line 13
So I comment out the line as shown below



Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            'MyBase.Dispose(disposing)
        End Try
    End Sub


Now no errors, why this works or what the designer.vb code does, don't ask me.
I'm happy and clueless, good enough for me for now 😂

No comments:

MySQL to MariaDB

 Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...