ItemsEvents_ItemAddEventHandler - only works in debugger

  • Thread starter Thread starter jsmith
  • Start date Start date
J

jsmith

Hello,

I'm trying to develop a C# VSTO 2005 SE Outlook Addin. My add-in is
based on the OutlookEvents VSTO Sample. I am trying to capture Inbox
ItemAdd events. What I am finding is that this works on my
development machine, but the event handler function is never called
when I deploy it to a test client machine. The addin is being loaded
on the client machine, I put a message boxes in the EventTracker
constructor before and after the ItemsEvents_ItemAddEventHandler is
added to inbox.ItemAdd. These message boxes are displayed on the
client machine. However, when a message arrives in the inbox, the
handler never executes.

I don't think this is the scope problem that I've read about in so
many threads where the Outlook.Items variable is local to a function
and goes out of scope. I have

public static Outlook.Items _inboxItems;

in my EventTracker class. In the EventTracker constructor, I have:

Outlook.NameSpace mapiNamespace = app.GetNamespace("MAPI");
Outlook.MAPIFolder inbox =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
as Outlook.MAPIFolder;
_inboxItems = inbox.Items;
_inboxItems.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InboxFolderItemAdded);


When I run this in the debugger on my development machine, the
InboxFolderItemAdded() function is called for every new message that
arrives in the inbox. When I run it on the test client,
InboxFolderItemAdded() is never called. Specs of my two systems
follow:

Dev Box:
Windows XP
Office 2003 SP2
Office 2003 PIA
VS 2005
VSTO 2005 SE
VSTO 2005 SE Runtime

Test Client:
Windows XP
Office 2003 SP2
Office 2003 PIA
VSTO 2005 SE Runtime


I did find this one msdn blog entry that suggests the Outlook.Items
member needs to be declared as public static:

http://blogs.msdn.com/jongallant/archive/2004/10/19/244820.aspx

However, I did this and it hasn't had any effect. Does anyone have
any insight about what I might be doing wrong here?
 
Hello,

I'm trying to develop a C# VSTO 2005 SE Outlook Addin. My add-in is
based on the OutlookEvents VSTO Sample. I am trying to capture Inbox
ItemAdd events. What I am finding is that this works on my
development machine, but the event handler function is nevercalled
when I deploy it to a test client machine. The addin is being loaded
on the client machine, I put a message boxes in the EventTracker
constructor before and after theItemsEvents_ItemAddEventHandleris
added to inbox.ItemAdd. These message boxes are displayed on the
client machine. However, when a message arrives in the inbox, the
handler never executes.

I don't think this is the scope problem that I've read about in so
many threads where the Outlook.Items variable is local to a function
and goes out of scope. I have

public static Outlook.Items _inboxItems;

in my EventTracker class. In the EventTracker constructor, I have:

Outlook.NameSpace mapiNamespace = app.GetNamespace("MAPI");
Outlook.MAPIFolder inbox =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
as Outlook.MAPIFolder;
_inboxItems = inbox.Items;
_inboxItems.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InboxFolderItemAdded);

When I run this in the debugger on my development machine, the
InboxFolderItemAdded() function iscalledfor every new message that
arrives in the inbox. When I run it on the test client,
InboxFolderItemAdded() is nevercalled. Specs of my two systems
follow:

Dev Box:
Windows XP
Office 2003 SP2
Office 2003 PIA
VS 2005
VSTO 2005 SE
VSTO 2005 SE Runtime

Test Client:
Windows XP
Office 2003 SP2
Office 2003 PIA
VSTO 2005 SE Runtime

I did find this one msdn blog entry that suggests the Outlook.Items
member needs to be declared as public static:

http://blogs.msdn.com/jongallant/archive/2004/10/19/244820.aspx

However, I did this and it hasn't had any effect. Does anyone have
any insight about what I might be doing wrong here?


A follow up: I have found that there is a single call to a function in
one of our libraries that causes the entire InboxFolderItemAdded()
event handler to not run. If I comment out this one call, the handler
runs. The handler looks something like this:

private void InboxFolderItemAdded( object addedItem )
{
MessageBox.Show("Received a mail message.");
if (addedItem is Outlook.MailItem )
{
Outlook.MailItem newItem = (Outlook.MailItem)addedItem;
if (newItem.Attachments.Count != 0))
{
MyAssembly.SomeFunction();
/* do some stuff */
MyAssembly.ProblematicFunction();
/* do some more stuff */
}
}
}

When I run my addin, the "Received a mail message" messagebox is never
displayed. However, if I comment out the call to
MyLibrary.ProblematicFunction(), it is shown for every message added
to the inbox. What might cause this? I know that MyAssembly is being
loaded, because the call to MyAssembly.SomeFunction() works just fine.

Notice that MyAssembly.ProblematicFunction() is only called if the
mail contains attachments. However, If I don't comment out the line,
the event handler does not run even for mail items that do not contain
attachments. That line's existence in the code causes the event
handler to not run.
 
Back
Top