none
Error: Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. RRS feed

  • Question

  • Hi,

    I am trying to send email from VB.Net using outlook, but am getting error at run time. PFB my code and help me please also am using visual studio 2005 and MS Office 2007 and reference added in the project is "Microsoft Outlook 12.0 object library"

     

    Imports Outlook = Microsoft.Office.Interop.Outlook
    
    Public Class Index
    
        Private Sub BSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BSend.Click
            Try
                ' Create an Outlook application.
                Dim oApp As Outlook._Application
                oApp = New Outlook.Application()
    
                ' Create a new MailItem.
                Dim oMsg As Outlook._MailItem
                oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
                oMsg.Subject = Me.TBSubject.Text
                oMsg.Body = Me.TBBody.Text
    
                ' TODO: Replace with a valid e-mail address.
                oMsg.To = Me.TBTo.Text
                ' Send
                oMsg.Send()
                MsgBox("Mail Send Successfully", MsgBoxStyle.Information)
                ' Clean up
                oApp = Nothing
                oMsg = Nothing
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    End Class
    

     

    In this above code i am getting error in the below line.

     

    oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
    

     


    Error is : 

     

    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: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
    
    

    thanks in advance

     


    Friday, January 6, 2012 6:17 PM

Answers

  • Hi M,

     

    Thanks for posting in the MSDN Forum.

     

    Sounds like you have a problem with your typelib registration.  Presumably, the Com interop layer is hitting the registry to try to locate the typelib.  It would start by looking under HKCR\Interface\{00063001-0000-0000-C000-000000000046}\Typelib.  The default value should refer to the guid for the typelib that defines the interface in question: which should be located under the following key: HKCR\Typelib\{00062FFF-0000-0000-C000-000000000046}.  There should be a version subkey and then a 0 subkey, and a win32 subkey under that.  The default value of the win32 key should point to the typelib (which is msoutl.olb).

     

    I'd recommend you check your Office directory for msoutl.olb.  If it is there, try running 'regtlib msoutl.olb'.  You should have regtlib on your machine is part of your Visual Studio install, I believe.  Anyway, reregistering the typelib will rewrite all of the necessary keys to the registry.  You will need administrative privileges for this operation. 

     

    The other possibility is that msoutl.olb itself is corrupt, in which case reinstalling Outlook should fix the problem.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 10, 2012 5:55 AM
    Moderator

All replies

  • I copied and pasted your code, made a few changes (I manually put in the Subject, Body, and To:) - the only other difference is that my interop library is version 14.0.0.0 and my VS is VS2010

    no errors here...

     

     

    Imports Outlook = Microsoft.Office.Interop.Outlook
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Try
                ' Create an Outlook application.
                Dim oApp As Outlook._Application
                oApp = New Outlook.Application()
    
                ' Create a new MailItem.
                Dim oMsg As Outlook._MailItem
                oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
                oMsg.Subject = "This is a test"
                oMsg.Body = "Hello everyone, how are you ?"
    
                ' TODO: Replace with a valid e-mail address.
                oMsg.To = "myemail@live.com"
                ' Send
                oMsg.Send()
                MsgBox("Mail Send Successfully", MsgBoxStyle.Information)
                ' Clean up
                oApp = Nothing
                oMsg = Nothing
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub
    End Class
    
    

    • Proposed as answer by Cor Ligthert Saturday, January 7, 2012 9:54 AM
    Friday, January 6, 2012 9:24 PM
  • try this. there's a significant difference between Microsoft Outlook 12.0 object library + Microsoft Outlook 14.0 object library:

     

    ' Create an Outlook application.
    Dim oApp As Outlook.ApplicationClass
    oApp = New Outlook.ApplicationClass()
    
    


    thanks for any help
    • Proposed as answer by Cor Ligthert Saturday, January 7, 2012 9:54 AM
    Friday, January 6, 2012 11:37 PM
  • Hi Paul,

     

    I have tried the above one but still am getting error

    Error :

    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: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

     

    plz give me the solution ASAP or plz give me any other way code to send email from outlook.

    Saturday, January 7, 2012 6:06 PM
  • Hi  Devon_Nullman

    can you plz tel me mail send successfully to the mentioned mail id. i am also able to run without error but am getting error at runtime.

    Saturday, January 7, 2012 6:08 PM
  • Hi M RameshKumar,

    Welcome to the MSDN forum.

    This forum is about Visual Basic in Visual Studio. I’m afraid that your topic about outlook is unsuitable here. For better support, I’ll move this thread to Outlook for Developers Forum.

    Sorry for any inconvenience and have a nice day.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 9, 2012 8:32 AM
    Moderator
  • Hi M,

     

    Thanks for posting in the MSDN Forum.

     

    Sounds like you have a problem with your typelib registration.  Presumably, the Com interop layer is hitting the registry to try to locate the typelib.  It would start by looking under HKCR\Interface\{00063001-0000-0000-C000-000000000046}\Typelib.  The default value should refer to the guid for the typelib that defines the interface in question: which should be located under the following key: HKCR\Typelib\{00062FFF-0000-0000-C000-000000000046}.  There should be a version subkey and then a 0 subkey, and a win32 subkey under that.  The default value of the win32 key should point to the typelib (which is msoutl.olb).

     

    I'd recommend you check your Office directory for msoutl.olb.  If it is there, try running 'regtlib msoutl.olb'.  You should have regtlib on your machine is part of your Visual Studio install, I believe.  Anyway, reregistering the typelib will rewrite all of the necessary keys to the registry.  You will need administrative privileges for this operation. 

     

    The other possibility is that msoutl.olb itself is corrupt, in which case reinstalling Outlook should fix the problem.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 10, 2012 5:55 AM
    Moderator
  • THank you Tom, this helped me.  I had a broken reference in Program Files. I'm not sure how it got there? I installed Office 14 but I can see that in both Program Files and Program Files x86. The Program Files one did not have msoutl.olb.

    Do you have any ideas why I would have Office 14 folders in 2 places??

    Friday, June 29, 2012 7:11 PM
  • Dear Tom_Xu

    I haven't got any HKCR\Typelib\ as a key or a value in my registery database.

    Could you indicate me how to fix it, pls?

    Mtx in advance


    Xavier Lefèvre

    Tuesday, August 28, 2012 10:00 AM