4

I'm working on a project where we're including the UmbracoCms NuGet package which internally uses the log4net framework version 1.2.11 to perform logging. Now we want to add another package (SharpRaven.Log4Net) which has a dependency on log4net 1.2.15. Just installing the second NuGet package yields an exception:

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

This is obviously because Umbraco is referencing the 1.2.11 version and my project is now referencing the 1.2.15 version, but how do I resolve this? I can't:

  • Change the version requirements of either package (really not willing to go build them from source)
  • Add both references to my project as they are the same component (VS won't allow it)
  • Remove the 1.2.15 version and add the 1.2.11 version. This gives me the same error, but then with the other version number.
  • Create a bindingRedirect because the required log4net versinos don't not have a publicToken.

I don't really see any other options, so any help would be appreciated.

Update to clarify why it's not a duplicate question of 3158928

I'd like to stress that the issue here is that the log4net assemblies that are referenced by the NuGet packages have a PublicKeyToken of null. The earlier question posted here Referencing 2 different versions of log4net in the same solution has some good answers, but does not have this problem and as such does not answer this question.

Community
  • 1
  • 1
Robba
  • 7,684
  • 12
  • 48
  • 76
  • You can use an empty publicKeyToken in an assembly redirect. I've solved the exact same issue with Umbraco's homegrown Log4Net and other references bringing in their own Log4Net version using the duplicate. – CodeCaster Sep 05 '16 at 10:50
  • Not sure how you did it then but for me a binding node without a PublicKeyToken was ignored completely. It also seems to contradict this MSDN page https://msdn.microsoft.com/en-us/library/7wd6ex19.aspx where it says: "if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly" where it speaks specifically about "strong named" assemblies. – Robba Sep 05 '16 at 13:39
  • I have no intention to go and discuss why it would or wouldn't work, so I have reopened the question. Good luck. – CodeCaster Sep 05 '16 at 13:40

1 Answers1

0

You can run the log4net versions side by side as in this awnser:

Basically you make a folder for each version and then bind it in your config:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="681549d62126b7b8" />
        <codeBase version="1.2.9.0" href="log4netv1.2.9.0\log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
        <codeBase version="1.2.10.0" href="log4netv1.2.10.0\log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
        <codeBase version="1.2.11.0" href="log4net.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Community
  • 1
  • 1
Peter
  • 27,590
  • 8
  • 64
  • 84
  • Thanks for the answer @Peter, but the two versions that are reference by the two NuGet packages do not have a publicKeyToken and adding a binding without one doesn't seem to work. – Robba Sep 05 '16 at 13:42