I am developing a VB.NET application that works synchronized with Outlook
Contacts, but at some certain records that I don't know I get an:
"An unhandled exception of type 'System.InvalidCastException' occurred in
..."
error when calling:
"objOutlookContactItem = objOutlookItems.GetNext"
The code that I am using is:
objOutlookItems = objOutlookFolder.Items
objOutlookContactItem = objOutlookItems.GetFirst
For j = 0 To objOutlookItems.Count - 1
System.Windows.Forms.Application.DoEvents()
If Not IsDBNull(objOutlookContactItem.Email1Address) Then
If Len(objOutlookContactItem.Email1Address) > 0 Then
chklstEpostalar.Items.Add(objOutlookContactItem.Email1Address)
End If
End If
lblToplam.Text = CStr(CLng(lblToplam.Text) + 1)
objOutlookContactItem = objOutlookItems.GetNext
Next
I don't get an error all records. For example on the 249th record I get it..
Is there any suggestions?