none
How to handle InlineResponse event in Outlook 2013 when use pre2013 PIA? RRS feed

  • Question

  • Hi,

    I have an vsto addin supporting OL2013, but using OL2010 PIA. I need to handle InlineResponse event using late binding trick.

    I have following code:

    public delegatevoidInlineResponseEventHandler(ObjectItem);

    _Explorer.GetType().GetEvent(

    "InlineResponse").AddEventHandler(_Explorer, newInlineResponseEventHandler(Explorer_InlineResponse_Event));

    privatevoidExplorer_InlineResponse_Event(objectItem)

            {        

            if(Item isOutlook.MailItem)

                { 

                }

            }

    But at runtime, I have exception thrown as below, when call AddEventHandler() method:

    Additional information: Object of type 'InlineResponseEventHandler' cannot be converted to type 'Microsoft.Office.Interop.Outlook.ExplorerEvents_10_InlineResponseEventHandler'.

    Any source code to follow to do this kind of work?

    Thanks

    jhou

    Monday, October 19, 2015 6:20 PM

All replies

  • Hello Jhou,

    Consider using interop files which corresponds to Outlook 2013. You just need to check Outlook's version at runtime and then subscribe to the email or not. You will not get any exception until you try to use the new members in old Outlook versions.

    Note, you can define the required types (missed) in your code as well.

    If you use .net framework 4.0 and above you may consider using the Embed Interop Types property of the references which allows to embed all the required types into the result assembly and avoid deploying interop assemblies at all.


    Monday, October 19, 2015 6:34 PM
  • Thanks for the suggestion.

    I found that this trick works.

    TypeevType=_Explorer.GetType().GetEvent("InlineResponse").EventHandlerType;

                    _Explorer.GetType().GetEvent(

    "InlineResponse").AddEventHandler(_Explorer, Delegate.CreateDelegate(evType, this, "Explorer_InlineResponse_Event", false));

                  

    where "Explorer_InlineResponse_Event" is the name of my handler function.

    Monday, October 19, 2015 7:05 PM