3rd party libraries refer to different versions of log4net.dll
Asked Answered
D

2

18

I have two different libraries critical to my application that are dependent on different versions of log4net.dll. Trying both dll's in my bin folder give the usual error when the 3rd party piece I'm using gets called:

Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Is there a way that the application can reference both dll's? The third party dll's are Windsor's IOC container and Paypal's API, both critical to this application.

Deport answered 7/12, 2010 at 20:22 Comment(1)
I'm going out on a limb here but I think you could ILMerge the assemblies even without owning the code and this would absolve that problem.Snocat
A
10

This question might have some answers that will help you.

Referencing 2 different versions of log4net in the same solution

Alternatively, if it is Windsor's Logging Facility that is dependent on log4net and not Windsor itself, you might be able to write your own log4net abstraction based on the version of log4net used by the PayPal API and tell Windsor to use that instead.

Here is the location of the log4net abstraction in Castle's source code repository: https://github.com/castleproject/Castle.Core/tree/master/src/Castle.Services.Logging.log4netIntegration

I don't use Castle so I cannot tell you how to configure it to reference your own log4net abstraction, but I bet it is not too difficult (assuming it is possible).

Here is a link to another post here on SO that describes configuring Castle with log4net. It also talks briefly about writing a custom logging logging facility:

Logging with Castle.Facilities.Logging and log4net

Good luck!

Arnettearney answered 7/12, 2010 at 20:38 Comment(1)
Thanks, the first link worked! By removing all project references to log4net.dll and instead using the app/web.config to create runtime references to the different versions, the application was able to find both dll's without complaining about a mismatch. See the wageoghe's "Referencing 2 different versions of log4net in the same solution" link for the details.Deport
R
1

Another route to go, I think, but I've never done it myself, is putting them in the GAC.

I believe you can have different versions of the same dll in the GAC, and you should be ok.

But I also might be crazy :)

Rainband answered 7/12, 2010 at 20:52 Comment(2)
Yes you can, but this is not an elegant solution.Flessel
You run into a scalability issue in that you have to perform the GAC install on every machine for this. Putting it into the .config allows this to be deployed with the application.Deport

© 2022 - 2024 — McMap. All rights reserved.