/
Handling conflicts with the log4net assembly version

Handling conflicts with the log4net assembly version

Problem

The S4S and G4S products include a dependency on a specific version of log4net. If another part of your project also includes a dependency on another version of the log4net assembly a System.TypeInitializationException will occur with an inner exception like:

{"Could not load file or assembly 'log4net, Version=1.2.13.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)":"log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"}

Solution 1

  1. Create sub folders in your project for each version of log4net you need to reference. Add the corresponding log4net.dll to each folder.
  2. Set "Copy to Output Directory" for each dll to "Copy always"
  3. Add a runtime section to the .config that indicates the location of each required log4net version.

    App.config runtime element for log4net versions
        <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
              <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
              <codeBase version="1.2.9.13" href="log4netv1.2.13.0\log4net.dll" />
            </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
              <codeBase version="1.2.15.0" href="log4netv1.2.10.0\log4net.dll" />
            </dependentAssembly>
          </assemblyBinding>
        </runtime>
  4.  

Solution 2

Load the required versions of log4net into the GAC and ensure the project references include the Version and PublicKeyToken details.

Related content

Installation
Installation
More like this
S4S Licensing
S4S Licensing
More like this
Testing a New or Updated Installation
Testing a New or Updated Installation
More like this
S4S Version Compatibility with Sitecore (Pre-Sitecore 9)
S4S Version Compatibility with Sitecore (Pre-Sitecore 9)
More like this
Web Server App Upgrade
Web Server App Upgrade
More like this
Developing with G4S
Developing with G4S
More like this