I've written a small Outlook VSTO addin which basically adds a context menu item to mail items. If selected the handler executes the following code:
try
{
    var selection = control.Context as Outlook.Selection;
    var mailItems = selection?.OfType<Outlook.MailItem>().ToList();
    var first = mailItems?.FirstOrDefault();
    if (first == null)
        return;
    var parent = first.Parent;
    if (parent != null && Microsoft.VisualBasic.Information.TypeName(parent) == "MAPIFolder")
        _application.Application.ActiveExplorer().CurrentFolder = parent;
}
catch (Exception ex)
{
    MessageBox.Show(null, ex.ToString(), "Error in GoToFolderOutlookAddIn", MessageBoxButtons.OK);
}
I'm using it to jump from a search results view to the folder where the mail resides and it works like a charm. BUT! If I right click on a mail item which is not the currently selected item, Outlook seems to jump to the correct folder but then crashes without any message box. What could be the problem? Am I not catching every and all exceptions that could occur?
Event viewer is not really helpful either: Exception code: 0xc0000005 so some kind of access violation error. But I'm not doing any native stuff.
 D.R.
 D.R.User contributions licensed under CC BY-SA 3.0