3

The Add In

I have written a VSTO Add-In for Outlook. The crux of the add-in is to put a button on the Ribbon when a user is replying to email that will allow them to quickly set the Email Sensitivity to Confidential or back to Normal. Currently the process to do this on an email is multiple steps, and my client wants it to be one click. The button icon is Red or Green based on the sensitivity of the current email.

Sensitivity = Normal => Red Button

Sensitivity = Confidential => Green Button

There are a few basic use cases I have uncovered:

  1. A user Creates a new Email
    • In this case the button should start Red and change when clicked.
  2. A user Creates a reply to an email
    • In this case the button should start the same color as the parent email. If the parent email was Red, the button should be Red and if it was Green the button should be Green
  3. A user Edits a draft
    • If the user has a draft the button should reflect the value of the Sensitivity property of the saved draft.

The way I chose to accomplish this was with two buttons in a ribbon XML where I override the getVisible property and based on the current MailItem set the appropriate button visible. Another way would have been to have one button and toggle the image and functionality based on MailItem sensitivity property.

Regardless of my choice I think I would have run into the same problem in that the Office Ribbon is meant to be a static object, drawn once at creation of the Explorer or Inspector and you need to force a redraw by calling the InvalidateUI method.

With that in mind, to cover my 3 use cases above I had to hook into some events from the application.

I'm not sure I can post the exact code, but the basics of it are as follows:

On Startup subscribe to:
    Application.ActiveExplorer().SelectionChange
    Application.Inspectors.NewInspector

On SelectionChange
    If there is one item selected, and that one item is a MailItem
        Refresh the Ribbon UI - Call Ribbon.InvalidateUI();

On NewInspector
    If the Inspector.CurrentItem is a MailItem
        Refresh the Ribbon UI - Call Ribbon.InvalidateUI();

The SelectionChange event handler covers if a user is clicking around in Outlook 2013 and up and selects an Inline Draft. It will draw the ribbon in the TabSet TabComposeTools, TabMessage. This places the icon on the main outlook window Ribbon when necessary.

The NewInspector event handler covers if the user double clicks on the draft, creating a new window.

The Problem

I have been receiving reports of Outlook crashing. At first I had limited logging and relied on the Event Logs generated by Outlook. Not very helpful.

Then I implemented log4Net, and I'm writing to a log file in the AppData folder of the user's profile. This has given me some insight

I have wrapped a try/catch around every method code block, so nothing in my add-in (that I wrote) runs outside of a try/catch, and each block just catches Exception, logs it, and throws it. This is an attempt to find the problem.

My latest log shows the UI refreshing, so it called my GetVisibility override, in there based on if the control.Context is an Explorer or Inspector I get the ActiveInlineResponse or CurrentItem as a MailItem, read the Sensitivity property and based on that return True or False if the button calling the handler should be visible. (I have one handler for both buttons)

The crash appears to happen when I am casting an ActiveInlineResponse to a MailItem. The next item in my log is the logging I do in the Startup handler of the Addin. (So the user restarted Outlook)

Other Details

  • The user base is currently running Outlook 2010 - Outlook 2016.
  • We have one add-in that runs on all of them as nothing we are doing should be specific to any version of office.
  • The add-in works without fail on Outlook 2010.
  • The add-in project selected was Outlook 2013-2016.
  • I'm using Ribbon XML over Designer because Designer doesn't support putting buttons in TabSets.

Update

I have put in some event handler local variables to my Add-In class as described by https://www.experts-exchange.com/questions/27305112/Problem-with-VSTO-event-handler-going-out-of-scope-in-Outlook-AddIn.html I haven't seen the error since, but also haven't had much feedback as I did this on a Friday and this Monday is a holiday. I'll update with an answer if this appears to be a "Fix".

Rob
  • 121
  • 9
  • 1
    What exception(s) are you getting? – stuartd Jan 12 '17 at 17:11
  • That's just it, there are none. It just crashes Outlook. The user gets a popup message reading "Microsoft Outlook has stopped working" with the options to "Check online for a solution" and "Restart the program". – Rob Jan 12 '17 at 17:15
  • [This question](http://stackoverflow.com/questions/1018745/word-vsto-swallows-exceptions-at-runtime-without-debugging) may be of use? – stuartd Jan 12 '17 at 17:17
  • Sorry, meant to CRLF there. There is an Exception Code of "c0000005", but I haven't found anything meaningful when searching for that. – Rob Jan 12 '17 at 17:18
  • That's an Access Violation Error, which is [uncatchable](http://stackoverflow.com/questions/2727784/uncatchable-accesviolationexception) ([or maybe not](http://stackoverflow.com/a/4759831/43846)) (That error code took me [back 20 years..!](https://support.microsoft.com/en-us/kb/230729)) – stuartd Jan 12 '17 at 17:36
  • I have this issue too with VSTO add-in for Word. In the addin, we have a winforms browser with adobe pdf loaded. If you lock the screen, and maybe close laptop screen, then open and unlock it, it always crashes with this access violation error. The way I figured out what was happening was by using "procdump.exe -ma -e winword.exe" you can download procdump from microsoft. Then when it crashes, you can load the dumpfile in Visual Studio – mdiehl13 Feb 14 '17 at 03:49

0 Answers0