Search code examples
c#excelbindingcom.net-assembly

Excel Object Library - app compiled using 16.0 and try to run using 12.0 on different computer


  1. I have Computer A with Office 2016 installed - including Office COM libraries to develope apps - Excel Object Library was used to create an app (Microsoft.Office.Interop.Excel ver 15.0.0.0 included in GAC) - great, app works great.

  2. I have computer B with Office 2007 installed - it includes Excel COM libraries in its GAC - ver 12.0.0.0 and ver 14.0.0.0. I want to run my app (from computer A) on this computer.

  3. I added App.config file to my WPF app as follows:

      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="Microsoft.Office.Interop.Excel"
                              publicKeyToken="71e9bce111e9429c"
                              culture="neutral" />
            <bindingRedirect oldVersion="15.0.0.0"
                             newVersion="12.0.0.0"/>
         </dependentAssembly>
    
         <dependentAssembly>
            <assemblyIdentity name="office"
                              publicKeyToken="71e9bce111e9429c"
                              culture="neutral" />
            <bindingRedirect oldVersion="15.0.0.0"
                             newVersion="12.0.0.0"/>
         </dependentAssembly>  
      </assemblyBinding> 
    

So I am trying to use older version of both libraries on computer where older version of Office in installed. I read that it is possible to set older version as the value of newVersion="". I include myApp.exe.config in my deployment but app still screams that it seems Excel not installed.

  1. My last resort would be to use a virtual machine with Office 2007 installed, download Visual Studio and recompile project updating references to older version of Excel Object Library - but maybe there is still another way to make my app work with Excel Object Library ver 12.0.0.0 on Computer B. I would be gratefull for any ideas before I decide to go with this 'virtual tank'.

Solution

    1. I simply removed \n from assemblyIdentity and bindingRedirect in App.config and it works now:

       <dependentAssembly>
          <assemblyIdentity name="Microsoft.Office.Interop.Excel" publicKeyToken="71e9bce111e9429c" culture="neutral" />
          <bindingRedirect oldVersion="15.0.0.0" newVersion="12.0.0.0"/>
       </dependentAssembly>
      
       <dependentAssembly>
          <assemblyIdentity name="office" publicKeyToken="71e9bce111e9429c" culture="neutral" />
          <bindingRedirect oldVersion="15.0.0.0" newVersion="12.0.0.0"/>
       </dependentAssembly>