How to redirect Assembly Versions in wpf?

2019-08-05 11:14发布

问题:

How to redirect Assembly Versions in WPF? Following http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx#bypass_PP throws File Load exception.

Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.Unity"
        publicKeyToken="31bf3856ad364e35"
        culture="neutral" />
      <!-- Assembly versions can be redirected in app, 
      publisher policy, or machine configuration files. -->
      <bindingRedirect oldVersion="2.1.505.0" newVersion="3.0.0.0" />
    </dependentAssembly>      
  </assemblyBinding>
</runtime>

回答1:

<configuration>  
  <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Practices.Unity"
            publicKeyToken="31bf3856ad364e35"
            culture="neutral" />
          <!-- Assembly versions can be redirected in app, 
          publisher policy, or machine configuration files. -->
          <bindingRedirect oldVersion="2.1.505.0" newVersion="3.0.0.0" />
        </dependentAssembly>      
      </assemblyBinding>
     </runtime>
</configuration >