I have a simple form that when filled out with a case # will return the name of the person that is handling the case. I am getting an error on any machine that does not have VS 2010 installed on it. The error is when ever the user uses the close button (the red X) at the top right of the form the following error is generated:
Code:
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.Windows.Forms.Form.Dispose(Boolean disposing)
   at Case_Info_Application.Form1.Dispose(Boolean disposing)
   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)
Here is the code for the form itself:
Code:
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim user As String = logon.user
        Dim pword As String = logon.pword

        Dim con As New SqlConnection(...)


        Dim i As Integer = 1
        Dim casenumbers As String

        If InStr(TextBox1.Text, "ME") Then
            casenumbers = TextBox1.Text
        Else
            casenumbers += "', '" & TextBox1.Text & "ME"
        End If
        If TextBox2.Text <> "" Then
            If InStr(TextBox2.Text, "ME") Then
                casenumbers += "', '" & TextBox2.Text
                i += 1
            Else
                casenumbers += "', '" & TextBox2.Text & "ME"
                i += 1
            End If
        End If
        If TextBox3.Text <> "" Then
            If InStr(TextBox3.Text, "ME") Then
                casenumbers += "', '" & TextBox3.Text
                i += 1
            Else
                casenumbers += "', '" & TextBox3.Text & "ME"
                i += 1
            End If
        End If
        If TextBox4.Text <> "" Then
            If InStr(TextBox4.Text, "ME") Then
                casenumbers += "', '" & TextBox4.Text
                i += 1
            Else
                casenumbers += "', '" & TextBox4.Text & "ME"
                i += 1
            End If
        End If





        Dim sql As New SqlCommand(command, con)
        Try
            con.Open()
            Dim reader As SqlDataReader
            reader = sql.ExecuteReader
            Dim sArray(i - 1) As String
            Dim x As Integer = 0
            While reader.Read

                sArray(x) = reader.Item(1).ToString
                x += 1
            End While
            Label1.Text = sArray(0)
            Label1.Show()
            If TextBox2.Text <> "" Then
                Label2.Text = sArray(1)
                Label2.Show()
            End If
            If TextBox3.Text <> "" Then
                Label3.Text = sArray(2)
                Label3.Show()
            End If
            If TextBox4.Text <> "" Then
                Label4.Text = sArray(3)
                Label4.Show()
            End If


            casenumbers = Nothing
        Catch ex As Exception
            MsgBox(ex)
        Finally
            con.Close()
            con.Dispose()
            sql.Dispose()
        End Try


    End Sub


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label1.Hide()
        Label2.Hide()
        Label3.Hide()
        Label4.Hide()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Try
            Me.Close()
        Catch ex As Exception
            MsgBox(ex)
        End Try


    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Me.Close()

    End Sub
End Class
The only collection that I see is the string array (sArray). I read that this issue occurs when the list is changed while being looped through but I don't see that here. Any Help?