View Single Post
  #1  
Old April 25th 08, 11:03 PM posted to microsoft.public.dotnet.languages.vb,microsoft.public.outlook,microsoft.public.outlook.program_vba
John[_11_]
external usenet poster
 
Posts: 30
Default Exception during Outlook Interop

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.olM ailItem),
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.InvalidComObjectExc eption
Message="COM object that has been separated from its underlying RCW
cannot be used."
Source="Interop.Outlook"
StackTrace:
at Outlook.ApplicationEvents_EventProvider..ctor(Obje ct )

What is the problem and how can I fix it?

Thanks

Regards


Ads
 

Mortgage - US Business Directory - Advertising - Mortgages - Online Loans