Ribbon Invalidate makes my outlook add-in crash-Collection of common programming errors
I have a pretty large outlook add-in with following ribbon.xml:
As you can see I have a couple of actions that require invalidation to enable, toggle… my buttons. My add-in starts up fine but crashes on some occasions. The following are some examples on which the add-in almost always crashes:
- Opening a mail item in a new inspector window and closing it again
- Multiple windows open, context menu with custom button in it is opened
The occasions in which it occurs make me pretty sure it has everything to do with the automatic invalidation on creation of a new context menu or ribbon, not when I call it myself. The error does not persist when I remove the getEnabled, getPressed… attributes. I can’t figure out a way to surpress the error instead of crashing or how to fix it. So if anybody can help or can give me more info on this it would be much appreciated. If you need any more code (like the getEnabled, getPressed… methods), let me know.
My invalidate methods. Note that most just return a boolean. These booleans are kept as a private variable inside the ribbon.cs class
public bool getEnabledToggleHistory(IRibbonControl control)
{
return toggleHistoryPanelState;
}
public bool getMailSelected(IRibbonControl control)
{
try
{
MailItem mailItem = getMail();
if (mailItem != null)
{
return true;
}
else
{
return false;
}
}
catch (System.Exception ex)
{
return false;
}
}
public bool getMailAndIDSelected(IRibbonControl control)
{
return mailAndIDSelected;
}
public bool getMailAndIDSelectedAndAttach(IRibbonControl control)
{
if (hasAttachments && mailAndIDSelected)
{
return true;
}
return false;
}
If I debug in a new Visual Studio instance I get the following:
Unhandled exception at 0x70B5B2A7 (MSO.DLL) in OUTLOOK.EXE: 0xC0000005: Access violation reading location 0x00000000.
If I debug the code from my solution I can never catch the error, nor does it say it has an unhandled one. It just crashes.