Could not load file or assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies
Asked Answered
H

3

18

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.

Houdon answered 17/3, 2017 at 7:33 Comment(20)
When you use bind redirect, you should always point to the latest version <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" /> see if this works. Also, make sure that in your entry project, you have this version of DLLSerge
@RaraituL sorry no luck with this. same exception.Houdon
Check your reference from .csproj. Does it point to the right dll file (is the path to log4net.dll correct?)Gunning
Check here, This might help you.Maighdlin
@Maighdlin I already tried this.Houdon
@CiprianLipan if you are pointing this <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> I can see different PublicKeyTokenHoudon
@CiprianLipan kindly see the update,Houdon
@Qadeer, do you have a single csproj file in your sln? It seems like you still have some references to log4net 1.2.10. If you have multiple projects, check all .csproj files for references to log4net.Gunning
@CiprianLipan I have updated references in all .csprojs with new version 2.0.8.0 and TokenKey 669e0ddf0bb1aa2a, cleaned solution rebuild, but same issueHoudon
All versions of a strong-named assembly must signed with the same key. It seems to me that the 2.0.8.0 assembly has a different public key token than the older assemblies. You have to sign the 2.0.8.0 assembly with the same public/private key pairs. In addition, make sure that the assembly exists in one of the directories shown at the end of the complete FusionLog. These are the locations checked by the runtime to find the assembly.Whirl
@HadiBrais replacing old or previous PublicKeyToken which is 1b44e1d426115821 with updated is all to do work. or I will have anything else for assigning thisHoudon
@HadiBrais by replacing token got thid error while rebuilding the solution CS0246 C# The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)Houdon
@Qadeer You'll have to update the reference to the assembly in the project configuration after signing it with the new key pair and remove the old reference.Whirl
updated. but same issueHoudon
@Qadeer CS0246 is a simple type-not-found error. Make sure that you have the right using statement, the assembly is correctly referenced, and that it is located in one of the directories in which the compiler looks up for it.Whirl
@HadiBrais yes I understand, but it comes when I changed the Token Key inside reference (as you said previously) , therefore reference changed and used .dll was not found.Houdon
please Check this post because same problem and solved.Jackijackie
have you tried consolidate nugets? maybe v1.2.10 still being used by other nuget?Azo
are you use correctly log4net.dll path and add to reference?Seam
yes, I am using updated version of log4net and its path is correctHoudon
M
7

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

Michal answered 23/3, 2017 at 21:43 Comment(2)
i am using IIS, does it matter ?Houdon
No, Apache is the creator of log4net, so I am not talking about the hosting service you use.Michal
L
0

In case this helps to someone,

I had similar issue for using log4net version 2.0.15, with log4net.ext.json version 2.0.10.1. I downgraded log4net.ext.json to 2.0.9.1 and the issue is gone.

Lockjaw answered 6/11, 2023 at 20:41 Comment(0)
F
0

Remember put this line on the start of your project XmlConfigurator.Configure();

Franckot answered 15/1, 2024 at 8:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.