Redirect Assembly Versions Using bindingRedirect Element

Sometimes it's mandatory to use a specific version of an assembly when various versions are available in place.

Simplest option is to use <bindingRedirect /> element under <dependentAssembly /> under <assemblyBinding /> in application configuration file.

For example in a configuration file that is presented below, version 1.0.0.0 of KeyvanAssembly is redirected to version 1.0.0.1.  Using this configuration file, application applies version 1.0.0.1 of KeyvanAssembly rather than version 1.0.0.0.

<configuration>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="KeyvanAssembly"

                          publicKeyToken="f405329a93f8ee7e"

                          culture="en-us" />

        <bindingRedirect oldVersion="1.0.0.0"

                        newVersion="1.0.0.1"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

A nice point is you can force your application to redirect all available versions of an assembly to a specific version using "*" wildcard:

<configuration>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="KeyvanAssembly"

                          publicKeyToken="f405329a93f8ee7e"

                          culture="en-us" />

        <bindingRedirect oldVersion="*"

                        newVersion="1.0.0.2"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

Now playing: Vangelis - Pulstar

[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.

3 Comments : 11.25.06

Feedbacks

 avatar
#1
Rui Silva
01.05.2007 @ 5:57 AM
Hi, I know that it is possible, with .net 2.0, to configure an application to run against a newer version of an assembly with: but i can't do the opposite way, that is: i'm right? Why? I think that with .net 1.1 the second scenario was also acomplished. best regards, Rui
 avatar
#2
fm164
12.08.2008 @ 3:39 PM

Hi,

Thanks for the tip.

This looks quite useful, though it did not work for me when I tried it... Is there anything else that is needed to be able to use the "*" wildcard?

Thank you

 avatar
#3
Pierre-Alain Vigeant
03.31.2009 @ 11:00 AM

You cannot specify a * for oldVersion, but you can specify a range.

The following will redirect everything before version 2.0.0.0 to the version 2.0.0.0:

<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>

Leave a Comment