outlookoffice365outlook-addincomaddinmessage-body

Outlook Crashing on Spellcheck when COM Add-In tries reading message


OUTLOOK VERSION: 2212 Build 15928.20282
32 Bit Outlook running on 64-Bit Win.

PRE-CONDITION:
Have a simple add-in which Overrides the InspectorActivate event handler.

RECREATE:
Open a new message Item
type in a few words and make a spelling error
Select the misspelled item, and LEFT click on one of the words suggested in the dropdown list.

When the event handler attempts to access the Body property of the Outlook MailItem a System.AccessViolation is thrown, and my exception handler is never reached.

mailItem = Inspector.CurrentItem as Outlook._MailItem;               

if (mailItem != null)
{
    try
    {
        if (mailItem.Body == null)  // System.AccessViolationException
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    catch(Exception e)
    {
       log.Error(e);
    }
 }

Solution

  • I implemented the following suggestion, and it's working

    This looks like an issue in the Outlook object model. I suggest that introduce a small delay before executing the logic which is now written in InspectorActivate. To achieve this, use the SendMessage/OnSendMessage machinery that we describe in section Wait a little; see the PDF file in the folder {Add-in Express}\Docs on your development PC. When the OnSendMessage event occurs and you filter out your message, get ActiveInspector and execute your logic for that Inspector object.

    For the code, look towards the bottom of the page Solution at Bottom of page