Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collection was modified enumeration operation may not execute

Status
Not open for further replies.

vladk

Programmer
May 1, 2001
991
0
0
US
Hi everyone,

How it would be possible to fix the exception in this procedure? Any help will be appreciated. Thank you!

Code:
   Public Sub LoadEmailAddress()

        Dim strRecipient As String
        Dim dicRecipients As New Dictionary(Of String, String)
        Dim dicCopyGroups As New Dictionary(Of String, clsGroup)
        Dim MyGroup As clsGroup

        Try

            For Each strGroup In gdicGroups.Keys

                dicRecipients.Clear()
    
                sqlReader = GetSqlReaderForEmailAddressesNew(gConn, gdicGroups(strGroup))

                While sqlReader.Read()
                    strRecipient = sqlReader("RecipientEmail").ToString

                    If strRecipient.Trim <> "" Then
                        If Not dicRecipients.ContainsKey(strRecipient) Then dicRecipients.Add(strRecipient, strRecipient)
                    End If
                   
                End While
                
                MyGroup = gdicGroups(strGroup)
                MyGroup.Recipients = dicRecipients

                '***** The next line throws the exception              
                dicCopyGroups.Add(strGroup, MyGroup)

            Next strGroup

            gdicGroups = dicCopyGroups

            sqlReader.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message & vbCr & ex.TargetSite.Name, "....", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub
 
Found the cause: it was byref call to GetSqlReaderForEmailAddressesNew.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top