Question

In my project I'm using two different third party components. I don't have access to the source code of these components.

Each component is referencing a different version of the same DLL assembly log4net.

In particular component A is referencing log4net version 1.2.9.0, while component B is referencing log4net version 1.2.10.0.

In VS2012, I'm currently adding to the references of my project the two third party components DLLs and I should add as well a reference to log4net.

I've tried the following:

1) Adding a reference to log4net 1.2.9.0: code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"

2) Adding a reference to log4net 1.2.10.0: code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"

3) Renaming the log4net.dll version 1.2.9.0 to log4netOld.dll and adding both the version 1.2.9.0 and the 1.2.10.0 to the project references: during compile time I get an expected warning telling that there is namespace clash, and the compiler resolves the types using 1.2.10.0, so at runtime I get the same problem as point 2 -> code compiles but at runtime I get exception "Could not load file or assembly [...] log4net, Version= 1.2.10.0 [...]"

I'm not expert at all of the Reference properties, our current setting for all references is:

1) alias: global

2) copy local: true

3) embed interop types: false

Any idea about how can I solve the problem ?

Was it helpful?

Solution

You should reference 1.2.10 in your solution and add a binding redirect in the app.config to point 1.2.9 to 1.2.10 - something like this:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.2.10.0" newVersion="1.2.10.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top