views:

330

answers:

2

I have a web application that uses the enterprise library for logging. I've recently been asked to use a 3rd party library that also has dependencies on the same enterprise library assemblies I'm using--except it uses different versions. I don't think I can throw the EL assemblies in the GAC (or maybe I can and I just don't know how), so I'm not sure how I can have multiple versions of the enterprise library in the same application. I can come up with some kludgey ways to get this to work by moving the 3rd party library stuff into another application and sending requests to that application some way, but does anyone know best practices on dealing with this scenario? Seems like there should be a better way to deal with this. Changing dependencies on the EL in my app and the 3rd party library isn't an option.

+1  A: 

I had the similar problem with Castle Windsor.

My solution: You can copy latest version of EL assemblies ( as far as I remember this is a Microsoft.Practices.ObjectBuilder2.dll and Microsoft.Practices.EnterpriseLibrary.Logging.dll) into the folder with your 3rd party library.

Then specify assembly version redirection to the latest version of EL assemblies in the Web.config file:

<configuration>
<runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
   <assemblyIdentity name="Microsoft.Practices.ObjectBuilder2" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
   <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0"/>
  </dependentAssembly>
  <dependentAssembly>
   <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
   <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
  </dependentAssembly>
 </assemblyBinding>
<runtime>
<configuration>

please check public key token and version of your EL

After this your application and 3rd party library both will use the latest version of EL.

Is this what you were asking for?

Alex
That might do it. I will give it a shot! Thanks!
pvanhouten
+1  A: 

I don't think you should have a problem.

From what I read, you reference Enterprise Library (let's say version 3.0) in your assemblies for logging. You are now required to use a 3rd party library that also references Enterprise Library -- but a different version (let's say version 3.1).

Enterprise Library is strong named so you can add different versions side by side to the GAC. Your assembly will locate the specific version that it references (version 3.0 in my example) while the 3rd party library will use the version that it references (version 3.1 in my example).

Configuration should also be OK since the types are fully qualified in the config file.

Tuzo
I might be wrong, but I think I tried adding the EL dlls to the GAC and they didn't have strong names.
pvanhouten
What versions are you dealing with? All EL versions 3.1 and above include pre-compiled strong named assemblies ( http://msdn.microsoft.com/en-us/library/cc511860.aspx ) so you should be able to add those to the GAC. For earlier versions of EL you have to sign and build those assemblies yourself.
Tuzo