Third-party components that reference different versions of the same assembly

In my project, I use two different third-party components. I do not have access to the source code of these components.

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

In particular, component A refers to log4net version 1.2.9.0, while component B refers to log4net version 1.2.10.0.

In VS2012, I am currently adding two third-party component DLLs to my project links, and I must add a link to log4net as well.

I tried the following:

1) Adding a link to log4net 1.2.9.0: compilation of the code, but at runtime I get the exception "Failed to load the file or assembly [...] log4net, Version = 1.2.10.0 [...]"

2) Adding a link to log4net 1.2.10.0: compilation of the code, but at runtime I get the exception "Failed to load the file or assembly [...] log4net, Version = 1.2.10.0 [...]"

3) Renaming the version of log4net.dll version 1.2.9.0 to log4netOld.dll and adding versions 1.2.9.0 and 1.2.10.0 to the project links: during compilation I get the expected warning that there is a conflicting namespace, and the compiler resolves types using 1.2.10.0, so at runtime I get the same problem as point 2 → compiling the code, but at runtime I get the exception "Could not load file or assembly [...] log4net, version = 1.2.10.0 [...] "

I am not an expert on all the properties of the Reference, our current setting is for all links:

1) alias: global

2) copy local: true

3) embed interaction types: false

Any idea on how I can solve the problem?

+2
source share
1 answer

You should reference 1.2.10 in your solution and add the binding redirection in app.config to paragraph 1.2.9 - 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> 
+1
source

All Articles