Troubleshooting Error – Unable to cast COM object {00063034-0000-0000-C000-000000000046}

Have you ever suffered from the following error while working with COM objects?

Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Outlook.MailItem’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{00063034-0000-0000-C000-000000000046}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I was a bit clueless why this is occurring even the code is perfect.

Dim fname, email, cname As String
Dim olContactItem As Outlook.ContactItem
Dim ContactsFolder As Outlook.MAPIFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

For i As Integer = 1 To ContactsFolder.Items.Count

If TypeOf (ContactsFolder.Items(i)) Is Outlook.ContactItem Then

olContactItem = ContactsFolder.Items(i)
fname = olContactItem.FirstName
email = olContactItem.Email1Address
cname = olContactItem.CompanyName

End If


Later came to know about the fact that the objects are not released by Garbage Collector even if we call it and nullify the object using Nothing keyword. Here are some points that we need to take care while coding with COM objects like ContactItem, MailItem etc.

  • Declare all objects explicitly and release them each pass through the loop using Marshal.ReleaseComObject()
  • Try using a for() loop rather than a foreach() loop, the foreach() is not only slower but also creates hidden instance variables
  • Make sure no compound dot operators are being used. Instantiate an explicit object for each dot operator, that way you can release them explicitly

Hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *