Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect assembly binding to the current version or higher?

Even though my references have Specific Version set to false, I'm getting assembly binding errors because the target machine has a higher version. How do I specify the current version or higher to avoid the following error when some target machines might have version 1.61.0.0 while others have 1.62.0.0 or higher?

System.IO.FileLoadException: Could not load file or assembly 'ServerInterface.NET, Version=1.61.0.0, Culture=neutral, PublicKeyToken=151ae431f239ddf0' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'ServerInterface.NET, Version=1.61.0.0, Culture=neutral, PublicKeyToken=151ae431f239ddf0'
like image 796
flipdoubt Avatar asked Jul 06 '15 21:07

flipdoubt


1 Answers

You need to add a Web.config / App.config key for a binding redirect like so (please change the versions to what you actually need):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="ServerInterface.NET" publicKeyToken="151ae431f239ddf0" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

The oldVersion attribute sets the range of versions to redirect. The newVersion attribute sets the exact version they should redirect to.

If you're using NuGet you can do this automatically through Add-BindingRedirect. Here's an article explaining it

See here for more information on binding redirects in general.

like image 70
Luke Merrett Avatar answered Oct 10 '22 02:10

Luke Merrett