Question

I have an Outlook 2010 Add-In project written in C# using Visual Studio 2010.

Since the Add-In is overall working in Outlook 2013 I just want to make a slight modification, to prevent problems with the new InlineResponse feature in Outlook 2013.

I want to register an eventhandler for the InlineResponse event without upgrading to VS 2012 (because of the removed installer project). I read about using reflections to get the new events.

I don't get any exceptions, but the event doesn't trigger my handler (OnInlineResponse not called).

public partial class ThisAddIn
{
   Outlook.Explorer _explorer;

   private void ThisAddIn_Startup(object sender, System.EventArgs e)
   {
       _explorer = Application.ActiveExplorer();

       AddInlineResponseHandler();
   }

   private void AddInlineResponseHandler()
   {
      var einfo = _explorer.GetType().GetEvent("InlineResponse", BindingFlags.Public | BindingFlags.Instance);

      if (einfo != null)
      {
         var handler = Delegate.CreateDelegate(einfo.EventHandlerType, this, this.GetType().GetMethod("OnInlineResponse", BindingFlags.NonPublic | BindingFlags.Instance), false);

         einfo.AddEventHandler(_explorer, handler);
      }

   }

   private void OnInlineResponse()
   {
      System.Windows.Forms.MessageBox.Show("InlineResponse");
   }
}

Any suggestions how I might achieve the desired behaviour?

Was it helpful?

Solution

Gavin Smyth (who wrote the mentioned post about using reflections) was so kind to give me an answer to the differences between our implementations:

from Gavin Smyth

The only difference I can spot between yours and mine is that OnInlineResponse takes an argument, the newly created mail item - see http://msdn.microsoft.com/en-us/library/office/jj229061 - ie, my method is defined as:

private void OnInlineResponse(object item)
{
  ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top