A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Exception during Outlook Interop



 
 
Thread Tools Search this Thread Display Modes
  #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: 83
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
  #2  
Old April 26th 08, 02:06 AM posted to microsoft.public.dotnet.languages.vb,microsoft.public.outlook,microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 4
Default 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!
  #3  
Old April 26th 08, 03:19 AM posted to microsoft.public.dotnet.languages.vb,microsoft.public.outlook,microsoft.public.outlook.program_vba
John[_11_]
external usenet poster
 
Posts: 83
Default 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!



  #4  
Old April 26th 08, 09:39 AM posted to microsoft.public.dotnet.languages.vb,microsoft.public.outlook,microsoft.public.outlook.program_vba
Mike Williams
external usenet poster
 
Posts: 4
Default 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




  #5  
Old April 26th 08, 09:41 AM posted to microsoft.public.dotnet.languages.vb,microsoft.public.outlook,microsoft.public.outlook.program_vba
Mike Williams
external usenet poster
 
Posts: 4
Default 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




 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 primary interop advise John Outlook - General Queries 4 February 5th 08 09:18 PM
Interop Assemblies for Outlook 2000 John Outlook - General Queries 1 February 4th 08 07:09 PM
How to get Microsoft.Office.Interop.Outlook.TaskItem from the IUnknown (C#) Godandag Add-ins for Outlook 5 April 5th 07 09:39 AM
Outlook Interop: Attachments.Add throws Exception Ferdinand Zaubzer Outlook and VBA 1 June 19th 06 03:10 PM
Outlook Interop COM Exception When Logged in as Windows Standard User [email protected] Add-ins for Outlook 0 April 27th 06 12:34 AM


All times are GMT +1. The time now is 07:17 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-2025 Outlook Banter.
The comments are property of their posters.