3

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 ?

Lorenzo Santoro
  • 464
  • 1
  • 6
  • 16
  • Possible duplicate of [Need a way to reference 2 different versions of the same 3rd party DLL](https://stackoverflow.com/questions/11550981/need-a-way-to-reference-2-different-versions-of-the-same-3rd-party-dll) – Orace Nov 20 '19 at 11:16

1 Answers1

2

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>
Trevor Pilley
  • 16,156
  • 5
  • 44
  • 60
  • Ciao Trevor, thanks for the hint! I've added the code to app.config, but I'm getting this compilation error: Error 97 The type 'log4net.Core.LoggingEvent' is defined in an assembly that is not referenced. You must add a reference to assembly 'log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=null'. I guess the problem is the Public Key Token, right ? – Lorenzo Santoro Feb 11 '14 at 12:31
  • It could be, what are the 3rd party DLLs you are using? Are there any more recent versions which target newer builds of log4net? – Trevor Pilley Feb 11 '14 at 13:51
  • the other 3rd party DLLs are other company components, and as far as I know there are no newer versions of any of them. – Lorenzo Santoro Feb 11 '14 at 14:28
  • By 'other company components' do you mean made by the company you work for? If that's the case, you could just update them to the same version of log4net yourself. – Trevor Pilley Feb 11 '14 at 14:30
  • Yes, they are components made by the same company, but they are used as well buy other software, and updating it's not a solution. But I've tried the concept and it works. The problem is that the publicKeytoken is null. I'll set the answer to resolved. Thanks for your help. – Lorenzo Santoro Feb 11 '14 at 15:09