COM Add-In Blocks Outlook From Closing Properly. I Think It's Aliv

N

Noel Weichbrodt

This bug has me backed into a dark alley.

My add-in, C# for Outlook, functions perfectly. But my testers report that
when it is loaded, Outlook will not close properly. When they exit Outlook,
the program hangs around for a while longer than normal (one user reported
ten minutes) before closing. During this time the taskbar icon is visible,
and they cannot launch another instance of Outlook (getting a "This operation
failed" error popup if they try). Upon opening outlook after exiting, they
get a progress bar that states something like "Outlook was closed improperly.
Rebuilding mailbox..." After a couple of minutes, Outlook is available and
working fine, until the next exit. This problem is reproducible.

I've reviewed my code several times in search of the cause. All my fields
are getting disposed of properly ondisconnection. No exceptions are occuring
anywhere during exit. I have no methods that are waiting for something. I can
find no explanation for this behavior besides an emergent demon coming from
my managed code.

Does anyone have an idea of what could be causing the improper closing? I'm
ready for a nExorcism.

I can post the ~750 loc source if requested.

TIA.

Noel
 
K

Ken Slovak - [MVP - Outlook]

After explicitly releasing all your objects are you also calling the garbage
collector? Many people have found they need to use MarshallReleaseCOMObject
as well as explicitly call the garbage collector to avoid the symptoms you
describe.
 
N

Noel Weichbrodt

Thanks for the reply, Ken.

public void OnBeginShutdown(ref System.Array custom)
{
try
{
//reportAsSpamButton = null;
confidentialityButton = null;
//replyAllButton = null;
addInInstance = null;
currentlySelectedMailEvents = null;
//explorer = null;
inspectors = null;

System.GC.Collect();
System.GC.WaitForPendingFinalizers();
}
catch (Exception e)
{
MMLib.Diagnostics.EventLogWriter.WriteToLog("MMIT Outlook Add-In",
e.ToString(), System.Diagnostics.EventLogEntryType.Error);
}
}

I am explicitely calling the gc after release. However, I am not
calling MarshallReleaseCOMObject, as I read that should not be done
unless specifically recommended. Am I running into a known bug, or is
the advice general for this kind of problem?
 
K

Ken Slovak - [MVP - Outlook]

I would try it and see if it helps. It seems to in enough cases that you'd
want to try calling MarshallReleaseCOMObject.
 

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