Search code examples
c#.netassembly-binding-redirect

Assembly Binding Redirect to a lower version


I am trying to downgrade a NServiceBus dependency so instead of using 4.0.0.0 to use 2.5.0.0

I am trying with the following ways, none of which seem to work.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="NServiceBus"
                              publicKeyToken="9fc386479f8a226c" culture="neutral"/>
            <bindingRedirect oldVersion="4.0.0.0" newVersion="2.5.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

I also tried with codebase :

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="NServiceBus"
                              publicKeyToken="9fc386479f8a226c"
                              culture="neutral"/>
            <codeBase version="2.5.0.0" href="NServiceBus.dll"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Still, nada. I went through the msdn documentation and there is no mention of using this capability in a backwards way. Is this possible?


Solution

  • I'm actually using your first statement for some interop DLLs because the clients in our company have a different state regarding office updates. This is the code I use :

    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="office" publicKeyToken="71E9BCE111E9429C" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="11.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
    

    This provides backwards compatibility from version 14 of the DLL to version 11. Could you provide a link to the DLL u are using?

    I've downloaded the NServiceBus framework (version 3.3.8) and inspected the DLL with ILSpy. I would suggest you do the same with your DLL. For my DLL it shows me the same public Key token as yours. Are you sure, that you use version 4.0.0.0 and not verision 3.3.0.0. Or you missmatched the public Key tokens perhaps.