J
John
Hi
I am using below code to send email from a vb.net app;
Public WithEvents OutlookApp As Outlook.Application
Dim ns As Outlook.NameSpace
OutlookApp = New Outlook.Application
ns = OutlookApp.GetNamespace("MAPI")
ns.Logon()
Dim em As Outlook.MailItem
em = CType(OutlookApp.CreateItem(Outlook.OlItemType.olMailItem),
Outlook.MailItem)
em.Display(False)
Marshal.ReleaseComObject(em)
ns.Logoff()
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(OutlookApp)
The code works fine for the first time but running it again produces the
following error;
System.Reflection.TargetInvocationException was unhandled by user code
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
InnerException: System.Runtime.InteropServices.InvalidComObjectException
Message="COM object that has been separated from its underlying RCW
cannot be used."
Source="Interop.Outlook"
StackTrace:
at Outlook.ApplicationEvents_EventProvider..ctor(Object )
What is the problem and how can I fix it?
Thanks
Regards
I am using below code to send email from a vb.net app;
Public WithEvents OutlookApp As Outlook.Application
Dim ns As Outlook.NameSpace
OutlookApp = New Outlook.Application
ns = OutlookApp.GetNamespace("MAPI")
ns.Logon()
Dim em As Outlook.MailItem
em = CType(OutlookApp.CreateItem(Outlook.OlItemType.olMailItem),
Outlook.MailItem)
em.Display(False)
Marshal.ReleaseComObject(em)
ns.Logoff()
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(OutlookApp)
The code works fine for the first time but running it again produces the
following error;
System.Reflection.TargetInvocationException was unhandled by user code
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
InnerException: System.Runtime.InteropServices.InvalidComObjectException
Message="COM object that has been separated from its underlying RCW
cannot be used."
Source="Interop.Outlook"
StackTrace:
at Outlook.ApplicationEvents_EventProvider..ctor(Object )
What is the problem and how can I fix it?
Thanks
Regards