Search code examples
c#vstooffice-interopoutlook-addin

VSTO Outlook AddIn: Cannot use Explorer Close event


some time ago I programmed an Outlook AddIn using NetOffice which worked very well. Now with the new Visual Studio Community 2017 I can program Office AddIns without the help of NetOffice. So I want to change my code, but I ran into a problem: I cannot subcsribe to the Explorer.Close event:

using Outlook = Microsoft.Office.Interop.Outlook;
namespace OLTest2
{
    public class ExplorerHandle
    {
        private Outlook.Explorer OutlookExplorer;
        public void InitExplorer(Outlook.Explorer expl)
        {
            OutlookExplorer = expl;
            // The next two lines compile:
            OutlookExplorer.BeforeItemPaste += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChange += SelectionChangeEvent;

            // ***Next line does not compile***:
            OutlookExplorer.Close += CloseEvent; // "Cannot assign to 'Close' because it is a 'method group'"
            
            // This is the old NetOffice code which worked fine:
            /* 
            OutlookExplorer.BeforeItemPasteEvent += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChangeEvent += SelectionChangeEvent;
            OutlookExplorer.CloseEvent += CloseEvent; 
            */ 
        }
    }
}

IntelliSense does not show me the existence of a Close event for an Outlook.Explorer object. But Microsoft tells me that such an event should exist:

Explorer events on MSDN

However, Visual Studio tells me that there's only a Close() method.

I'm missing something, but what?


Solution

  • You need to cast OutlookExplorer variable above to ExplorerEvents interface.