C# – Could not load file or assembly ‘log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821’ or one of its dependencies

.net-assemblyasp.netclog4netnet

I found several threads relating this issue, but none of those solved my issue.

I have been previously using log4net version 1.2.10.0 in my ASP.NET services. I have updated it to current version which is log4net v2.0.8.0, due to some third party libraries I also added the following lines in my web.config to to support/redirect old versions.

<runtime>    
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>      
      <dependentAssembly>
       <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-1.2.10.0" newVersion="2.0.8.0" />      
      </dependentAssembly>    
    </assemblyBinding>
</runtime>

I am also confused in these Messages
Inner Exception: ((System.IO.FileLoadException)ex.InnerException.InnerException).Message

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)

Exception Message:

Could not load file or assembly 'log4net, Version=2.0.8.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)

probably the following lines pointing to issue in FusionLog

WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY
TOKEN ERR: Failed to complete setup of assembly (hr = 0x80131040).
Probing terminated

Complete FusionLog

=== Pre-bind state information === LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821
(Fully-specified) LOG: Appbase = file:///F:/Cab Management
System/CMS-Localized/CMS-Code/WebServices/CMSAPI/ LOG: Initial
PrivatePath = F:\Cab Management
System\CMS-Localized\CMS-Code\WebServices\CMSAPI\bin Calling assembly
: paypal_base, Version=4.4.55.0, Culture=neutral,
PublicKeyToken=b37401294aaf5617.
=== LOG: This bind starts in default load context. LOG: Using application configuration file: F:\Cab Management
System\CMS-Localized\CMS-Code\WebServices\CMSAPI\web.config LOG: Using
host configuration file:
C:\Users\Dell\Documents\IISExpress\config\aspnet.config LOG: Using
machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 1.2.10.0
redirected to 2.0.8.0
. LOG: Post-policy reference: log4net,
Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821 LOG:
Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/vs/864fb64d/ad78f51e/log4net.DLL. LOG: Attempting
download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/vs/864fb64d/ad78f51e/log4net/log4net.DLL. LOG:
Attempting download of new URL file:///F:/Cab Management
System/CMS-Localized/CMS-Code/WebServices/CMSAPI/bin/log4net.DLL. WRN:
Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing
terminated.

Suggestion

do I need to put both .dll in the /bin folder,

Stack Traces

at com.paypal.sdk.profiles.BaseAPIProfile..ctor() at
com.paypal.sdk.profiles.ProfileFactory.createSignatureAPIProfile()
at PayPalLibrary.PayPalPayment.SetPaymentProfile(String rsUserName,
String rsPassword, String rsSignature, String rsEnviroment, String
rsIpAddress) in F:\path\Classes\PayPalPayment.cs:line 34 at
API.ServiceBLL.DoCreditCardPayment(String txtNameOnCard, String
ddlExpiryMonth, String ddlExpiryYear, String txtCardNo, String txtCv2,
String amount, String& paymentServiceType) in
F:\Path\ServiceBLL.cs:line 2907

Update

after the suggestion of Ciprian Lipan in comments, I found this entry in .csproj in which PublicKeyToken was different from my web.config I copied this token and replaced in config and got only exception message, inner exception gone. bellow is entry in .csproj

<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
      <HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
      <Private>True</Private>
</Reference>

Exception

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)

however I chnaged the token in config with new one found in .csproj

FusionLog

=== Pre-bind state information === LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821
(Fully-specified) LOG: Appbase = file:///F:/Path/API/ LOG: Initial
PrivatePath = F:\path\API\bin Calling assembly
: paypal_base, Version=4.4.55.0, Culture=neutral,
PublicKeyToken=b37401294aaf5617.
=== LOG: This bind starts in default load context. LOG: Using application configuration file: F:\path\API\web.config LOG: Using
host configuration file:
C:\Users\me\Documents\IISExpress\config\aspnet.config LOG: Using
machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: log4net, Version=1.2.10.0,
Culture=neutral, PublicKeyToken=1b44e1d426115821 LOG: Attempting
download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/vs/864fb64d/ad78f51e/log4net.DLL. LOG: Attempting
download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/vs/864fb64d/ad78f51e/log4net/log4net.DLL. LOG:
Attempting download of new URL file:///F:/path/API/bin/log4net.DLL. WRN:
Comparing the assembly name resulted in the mismatch: Major Version

ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing
terminated.

Best Answer

Apache decided to change their public key, arg! There is a solution in a similar post here.

Or you could revert your reference to the older 1.2.10.0 version with the old public key token. nuget log4net 1.2.10.0