How to use two different NuGet packages with different log4net version requirements

I am working on a project in which we include the UmbracoCms NuGet package, which internally uses log4net version 1.2.11 to complete registration. Now we want to add another package (SharpRaven.Log4Net), which has a dependency on log4net 1.2.15. Just installing the second NuGet package gives 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 
manifest definition does not match the assembly reference. (Exception from 
HRESULT: 0x80131040)

This is obviously because Umbraco is referencing version 1.2.11, and my project is now referencing version 1.2.15, but how do I solve this? I can not:

  • Change the version requirements of any package (really not wanting to build them from the source)
  • Add both links to my project as they are the same component (VS will not allow)
  • Remove version 1.2.15 and add version 1.2.11. This gives me the same error, but then with a different version number.
  • Create a bindingRedirect because the required versions of log4net do not have a publicToken.

I see no other options, so any help would be appreciated.

Refresh to clarify why this is not a duplicate question 3158928

I would like to emphasize that the problem is that the log4net assemblies referenced by the NuGet packages have a PublicKeyToken null. The earlier question posted here Link to 2 different versions of log4net in the same solution contains some good answers, but does not have this problem and, as such, does not answer this question.

+4
source share
1 answer

log4net , awnser:

, :

<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>
0

Source: https://habr.com/ru/post/1653572/


All Articles