Error: Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to inte

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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"

<div style="color:black; background-color:white
<pre><span style="color:blue Imports Outlook = Microsoft.Office.Interop.Outlook

<span style="color:blue Public <span style="color:blue Class Index

<span style="color:blue Private <span style="color:blue Sub BSend_Click(<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles BSend.Click
<span style="color:blue Try
<span style="color:green Create an Outlook application.
<span style="color:blue Dim oApp <span style="color:blue As Outlook._Application
oApp = <span style="color:blue New Outlook.Application()

<span style="color:green Create a new MailItem.
<span style="color:blue Dim oMsg <span style="color:blue As Outlook._MailItem
oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
oMsg.Subject = <span style="color:blue Me.TBSubject.Text
oMsg.Body = <span style="color:blue Me.TBBody.Text

<span style="color:green TODO: Replace with a valid e-mail address.
oMsg.<span style="color:blue To = <span style="color:blue Me.TBTo.Text
<span style="color:green Send
oMsg.Send()
MsgBox(<span style="color:#a31515 "Mail Send Successfully", MsgBoxStyle.Information)
<span style="color:green Clean up
oApp = <span style="color:blue Nothing
oMsg = <span style="color:blue Nothing
<span style="color:blue Catch ex <span style="color:blue As Exception
MsgBox(ex.Message)
<span style="color:blue End <span style="color:blue Try
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue End <span style="color:blue Class
[/code]


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

<div style="color:black; background-color:white
<pre>oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
[/code]


<br/>
Error is :

<div style="color:black; background-color:white
<pre>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)).

[/code]

<br/>
thanks in advance<br/>
<br/>

<br/>

View the full article
 
Back
Top