Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook - General Queries (http://www.outlookbanter.com/outlook-general-queries/)
-   -   Exception during Outlook Interop (http://www.outlookbanter.com/outlook-general-queries/70978-exception-during-outlook-interop.html)

John[_11_] April 25th 08 11:03 PM

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



[email protected] April 26th 08 02:06 AM

Exception during Outlook Interop
 
Dear John,

Have you tried putting Marshal.ReleaseComObject(em) after
ns.Logoff() ??

Hope that helps.
CreateWindow
http://mymessagetaker.com
The while-you-were-out message program you have been looking for!

John[_11_] April 26th 08 03:19 AM

Exception during Outlook Interop
 
Hi

Tried

ns.Logoff()
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(em)
Marshal.ReleaseComObject(OutlookApp)

and

ns.Logoff()
Marshal.ReleaseComObject(em)
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(OutlookApp)

Still no luck.

Thanks

Regards

wrote in message
...
Dear John,

Have you tried putting Marshal.ReleaseComObject(em) after
ns.Logoff() ??

Hope that helps.
CreateWindow
http://mymessagetaker.com
The while-you-were-out message program you have been looking for!




Mike Williams April 26th 08 09:39 AM

Exception during Outlook Interop
 
"John" wrote in message
...


I am using below code to send email from a vb.net app;


I don't know whether anyone from Microsoft regularly reads the Visual Basic
groups but if they do then I am very surprised that they permit one of their
own MVPs to engage in such outrageous long term trolling activities in one
of their own public newsgroups, such as the activity that the person who
purports to be Bill McCarthy has engaged in on the
microsoft.public.vb.general.discussion group for many months. If this man
belongs to you:

https://mvp.support.microsoft.com/pr...9-25680609CCB8

.. . . then perhaps you might like to look at his activity in that group.
Here for example is one of his very latest offerings:

"Bill McCarthy" wrote in message
...

Yeh, still a way to go. I think given the warm reaction today,
and given some folks have learning difficulties around here
(obviously why they are still *stuck* in VB6 *only*), might
just have to ramp things up a notch or two, and make it more
toasty :D





Mike Williams April 26th 08 09:41 AM

Exception during Outlook Interop
 
"John" wrote in message
...

Hi
Tried
ns.Logoff()


I don't know whether anyone from Microsoft regularly reads the Visual Basic
groups but if they do then I am very surprised that they permit one of their
own MVPs to engage in such outrageous long term trolling activities in one
of their own public newsgroups, such as the activity that the person who
purports to be Bill McCarthy has engaged in on the
microsoft.public.vb.general.discussion group for many months. If this man
belongs to you:

https://mvp.support.microsoft.com/pr...9-25680609CCB8

.. . . then perhaps you might like to look at his activity in that group.
Here for example is one of his very latest offerings:

"Bill McCarthy" wrote in message
...

Yeh, still a way to go. I think given the warm reaction today,
and given some folks have learning difficulties around here
(obviously why they are still *stuck* in VB6 *only*), might
just have to ramp things up a notch or two, and make it more
toasty :D






All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com