Exception with Outlook addin

D

Dorian

I've developed an Outlook 2007 addin with VS2008 that gathers MailItem
information for insertion to a database. I handle the
Explorer.SelectionChange event and for some reason an exception is getting
logged with a few installs in the office:

System.Runtime.InteropServices.COMException (0xBBC40114): Outlook has
already begun transmitting this message.
at Microsoft.Office.Interop.Outlook._MailItem.get_EntryID()
at OutlookTracker.ThisAddIn.Explorer_SelectionChange()

Code:

private void Explorer_SelectionChange()
{
try
{
if (m_Explorer != null)
{
// We only care if there is a single collection
Selection sel = m_Explorer.Selection;
if (sel.Count == 1)
{
object item = sel[1];
if (item is MailItem)
{
MailItem mail = (MailItem)item;

if (vmHandler.LastItemId != mail.EntryID)
{
...Additional code here...
}
}
}
}
}
}
catch (Exception ex)
{
// Log error here
}

vmHandler is a class that facilitates the insertion to the database on a new
thread.

Anyone know what exactly is going on and how to make sure it doesn't occur?
 
K

Ken Slovak - [MVP - Outlook]

Are those users selecting anything in Outbox or selecting items due to be
sent out? That's the only reason I can think of for that error.
 
D

Dorian

That's always a possibility. My biggest concern is somehow detecting when the
message is being transmitted before I try and access the EntryID. My first
guess is to check if the MailItem exists in the Outbox. Is there a better way
to check for a MailItem being sent?

Ken Slovak - said:
Are those users selecting anything in Outbox or selecting items due to be
sent out? That's the only reason I can think of for that error.




Dorian said:
I've developed an Outlook 2007 addin with VS2008 that gathers MailItem
information for insertion to a database. I handle the
Explorer.SelectionChange event and for some reason an exception is
getting
logged with a few installs in the office:

System.Runtime.InteropServices.COMException (0xBBC40114): Outlook has
already begun transmitting this message.
at Microsoft.Office.Interop.Outlook._MailItem.get_EntryID()
at OutlookTracker.ThisAddIn.Explorer_SelectionChange()

Code:

private void Explorer_SelectionChange()
{
try
{
if (m_Explorer != null)
{
// We only care if there is a single collection
Selection sel = m_Explorer.Selection;
if (sel.Count == 1)
{
object item = sel[1];
if (item is MailItem)
{
MailItem mail = (MailItem)item;

if (vmHandler.LastItemId != mail.EntryID)
{
...Additional code here...
}
}
}
}
}
}
catch (Exception ex)
{
// Log error here
}

vmHandler is a class that facilitates the insertion to the database on a
new
thread.

Anyone know what exactly is going on and how to make sure it doesn't
occur?
 
K

Ken Slovak - [MVP - Outlook]

You don't want to do that. Accessing the item in Outbox will either cause
that error or cancel the send depending on what stage it is in the
transport. You also can't tell if Outlook has started an automatic
send/receive or the user has manually started one. So you're out of luck
with that.
 
D

Dorian

And of course there's no way for me to check for that specific exception and
disregard it, is there?
 
K

Ken Slovak - [MVP - Outlook]

I believe it comes out before you'd see it in your code. You certainly can
enclose your code in a try...catch block and you can even specifically trap
COM exception errors, but in my experience you often see the error message
in the UI even with the exception trapped. That just prevents your code from
completing execution correctly.
 
D

Dorian

From what I can tell the exceptions are being caught before they are
displayed by Outlook, but they're also being logged. I don't want to filter
out ALL ComExceptions since there might be some obscure ones come up in the
future, but since this one is unavoidable I'd like to filter it from being
logged.
 
K

Ken Slovak - [MVP - Outlook]

So in that case handle the exceptions and look for that one, whatever it is.
You might have to get one of those exceptions to see exactly what it is and
it might be the same as various others though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top