Quantcast
Channel: Visual Studio Tools for Office (VSTO) forum
Viewing all articles
Browse latest Browse all 5157

Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type

$
0
0

I have written an Office Tools application (not an Outlook Add-in, but rather a standalone tool) that uses the Word, Excel, and Outlook Interops.  The application builds and compiles with no errors.

However, the last step is to create an email with this code:

Sub SendDocumentAsAttachment(emailBodyText As String, Addressee As String)

        Dim oOutlookApp As Microsoft.Office.Interop.Outlook.Application
        Dim oItem As Microsoft.Office.Interop.Outlook.MailItem

        oOutlookApp = New Microsoft.Office.Interop.Outlook.Application()
        oItem = oOutlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)

        With oItem
            .To = Addressee
            .Subject = "Committee Meeting Announcement"
            .Body = emailBodyText
        End With

        oItem.Display()

        oItem = Nothing
        oOutlookApp = Nothing

    End Sub

The subject error occurs at this step:

        oItem = oOutlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)

The error is:

System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).'

I have researched this error and am not sure why it occurs.  I have a brand new machine (there was never any other version Outlook installed) so I don't have a version error in the registry.  I have confirmed this by looking for anything other than version 9.6 in the registry for the {00063001-0000-0000-C000-000000000046} keys.  

I have also confirmed that the MSOUTL.OLB is properly registered (it is).

Any help would be greatly appreciated.  Also, I don't know why the the text size of this post is changing as I type it.  Weird.

Thanks



Viewing all articles
Browse latest Browse all 5157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>