none
Using reflection on primary inteop assemblies that are not resisted on the client machine RRS feed

  • Question

  • Hi,
    I've developed an add-in to Outlook 2007 that uses classes from primary interop assemblies (e.g : Microsoft.office.interop.outlook)
    When I deploy my add-in to client machine where those PIA assemblies are not registered (but exists in the same folder where my add-in assembly is) everything works fine, BUT when I try to use reflection on a class/interface that defined in PIA assembly it fails.
    My question is how reflection works on interop classes ,Why when I only using managed code I need to register my interop assemblies (regasm on the interop assemblies solves the issue)
    Thanks,
    Oren.
    Oren
    Tuesday, November 10, 2009 8:13 PM

Answers

  • I might know what went wrong , There are two scenarios (when PIA is not registered on the client machine) : 1. Using a downcast to the managed interface on the com object , this will work since the interface defined the dispid for the RCW so it's like accessing to the VTable itself of the com object. 2.Using reflection - this will fail since the RCW can't translate the CLSID of the com object to a managed interface therefore resulting in an empty type information Am I right on this one ? Thanks, Oren.
    Oren
    Thursday, November 12, 2009 10:25 AM

All replies

  • It could be beacuse version of PIA on the target machine is different than the version of PIA send with the installer.
    Wednesday, November 11, 2009 10:05 AM
  • Thanks Amit for the idea!

    Hello Oren

    Could you please let us know the version of Office installed on that machine? Could you please post the reflection code that failed? Generally speaking, late binding through .NET Reflection does not require any interop assembly or PIA. http://support.microsoft.com/default.aspx/kb/302902.

    Additionally, you may consider deploying Office PIA with your addin:
    http://blogs.msdn.com/vsto/archive/2008/05/08/adding-the-office-primary-interop-assemblies-as-a-prerequisite-in-your-clickonce-installer-mary-lee.aspx


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, November 11, 2009 12:29 PM
    Moderator
  • Thanks Amit for the idea!

    Hello Oren

    Could you please let us know the version of Office installed on that machine? Could you please post the reflection code that failed? Generally speaking, late binding through .NET Reflection does not require any interop assembly or PIA. http://support.microsoft.com/default.aspx/kb/302902 .

    Additionally, you may consider deploying Office PIA with your addin:
    http://blogs.msdn.com/vsto/archive/2008/05/08/adding-the-office-primary-interop-assemblies-as-a-prerequisite-in-your-clickonce-installer-mary-lee.aspx


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com .
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Hi,
    Thanks for your quick answer,
    I suspected the PIA version but got no result on this path. Office 2007 is installed on the client machine (no service packs)
    The code is very straight forward :

    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
            {
                applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
                doSomeReflectionStuff();
               
            }
     private void doSomeReflectionStuff()
            {
                System.Windows.Forms.MessageBox.Show("doSomeReflectionStuff");
                PropertyInfo[] infos = applicationObject.GetType().GetProperties();
                foreach (PropertyInfo info in infos)
                {
                    System.Windows.Forms.MessageBox.Show(info.Name);
                }
            }

    I can't deploy the PIA on the client machine since dosing so may requires administrative privileges (which the client may don't have)
    Oren.

    Oren
    Wednesday, November 11, 2009 7:08 PM
  • I might know what went wrong , There are two scenarios (when PIA is not registered on the client machine) : 1. Using a downcast to the managed interface on the com object , this will work since the interface defined the dispid for the RCW so it's like accessing to the VTable itself of the com object. 2.Using reflection - this will fail since the RCW can't translate the CLSID of the com object to a managed interface therefore resulting in an empty type information Am I right on this one ? Thanks, Oren.
    Oren
    Thursday, November 12, 2009 10:25 AM