473,513 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jun 27 '08 #1
4 1425
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!
Jun 27 '08 #2
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

<cr**********@gmail.comwrote in message
news:f5**********************************@u12g2000 prd.googlegroups.com...
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!

Jun 27 '08 #3
"John" <in**@nospam.infovis.co.ukwrote in message
news:es****************@TK2MSFTNGP06.phx.gbl...

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" <Bi**@N0SPAM.comwrote in message
news:19**********************************@microsof t.com...
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


Jun 27 '08 #4
"John" <in**@nospam.infovis.co.ukwrote in message
news:uJ**************@TK2MSFTNGP04.phx.gbl...
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" <Bi**@N0SPAM.comwrote in message
news:19**********************************@microsof t.com...
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


Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
4162
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
7
2661
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
4
19287
by: John | last post by:
Hi Does anyone have a vb.net example of how to use redemption to send mail through outlook? Many Thanks Regards
9
6715
by: Srinivas | last post by:
hi all how to access the outlook user profiles through VB.net any help.... thanks in advanc Srinivas
7
3590
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i...
2
7266
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
11
7000
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
1
3208
by: =?Utf-8?B?cm9i?= | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
1
2837
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.