M
Magnus
Hello,
I'm trying to go through all contacts, and compare them to all other contacts, to see if they are similar etc etc.
I seems to exceeds the limit of approx 255 open com objects, and I can't figure out how to get my code to work.
As you can see I try to delete the objects, but I can't succeed.
My error which I get after several loops:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063021-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
in the top I have: using ol = Microsoft.Office.Interop.Outlook;
and my procedure simplified:
ol.Application objOutlook = new ol.Application();
ol.MAPIFolder folder = objOutlook.Session.GetDefaultFolder(ol.OlDefaultFolders.olFolderContacts);
ol.Items items = (ol.Items) folder.Items;
int i = 1; int tot = items.Count; int dups = 0;
string dupindexes = "none";
ol.ContactItem[] RemoveItems = new Microsoft.Office.Interop.Outlook.ContactItem[10000];
foreach (ol.ContactItem itm in items)
{
int inclausecount = 0;
ol.MAPIFolder folder2 = objOutlook.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts );
ol.Items items2 = (ol.Items) folder2.Items;
foreach (ol.ContactItem itm2 in items2)
{
inclausecount++;
if (itm.CreationTime <= itm2.CreationTime) goto notmatch;
if (itm.Subject != itm2.Subject) goto notmatch;
dups++;
dupindexes += i.ToString() + ":" + itm.Subject + "\r\n";
itm2.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm2);
GC.Collect();
break;
notmatch:
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm2);
GC.Collect();
}
label1.Text = i.ToString() + "/" + tot.ToString() + ": Dups found: " + dups + "\r\n" + dupindexes;
i++;
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm);
GC.Collect();
}
Please help /Magnus
I'm trying to go through all contacts, and compare them to all other contacts, to see if they are similar etc etc.
I seems to exceeds the limit of approx 255 open com objects, and I can't figure out how to get my code to work.
As you can see I try to delete the objects, but I can't succeed.
My error which I get after several loops:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063021-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
in the top I have: using ol = Microsoft.Office.Interop.Outlook;
and my procedure simplified:
ol.Application objOutlook = new ol.Application();
ol.MAPIFolder folder = objOutlook.Session.GetDefaultFolder(ol.OlDefaultFolders.olFolderContacts);
ol.Items items = (ol.Items) folder.Items;
int i = 1; int tot = items.Count; int dups = 0;
string dupindexes = "none";
ol.ContactItem[] RemoveItems = new Microsoft.Office.Interop.Outlook.ContactItem[10000];
foreach (ol.ContactItem itm in items)
{
int inclausecount = 0;
ol.MAPIFolder folder2 = objOutlook.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts );
ol.Items items2 = (ol.Items) folder2.Items;
foreach (ol.ContactItem itm2 in items2)
{
inclausecount++;
if (itm.CreationTime <= itm2.CreationTime) goto notmatch;
if (itm.Subject != itm2.Subject) goto notmatch;
dups++;
dupindexes += i.ToString() + ":" + itm.Subject + "\r\n";
itm2.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm2);
GC.Collect();
break;
notmatch:
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm2);
GC.Collect();
}
label1.Text = i.ToString() + "/" + tot.ToString() + ": Dups found: " + dups + "\r\n" + dupindexes;
i++;
System.Runtime.InteropServices.Marshal.ReleaseComObject(itm);
GC.Collect();
}
Please help /Magnus