无法加载文件或程序集“log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821”或其依赖项。

17

我发现有几个线程与这个问题相关,但没有一个解决了我的问题。

我之前在我的 ASP.NET服务中使用的是log4net版本1.2.10.0。我已将其更新到当前版本log4net v2.0.8.0,由于一些第三方库,我还添加了以下行到我的web.config以支持/重定向旧版本。

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

在这些消息中,我也感到困惑

内部异常: ((System.IO.FileLoadException)ex.InnerException.InnerException).Message

无法加载文件或程序集 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' 或其中之一的依赖项。所定位的程序集清单定义与程序集引用不匹配。(HRESULT 的异常:0x80131040)

异常消息:

无法加载文件或程序集 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' 或其中之一的依赖项。所定位的程序集清单定义与程序集引用不匹配。(HRESULT 的异常:0x80131040)

可能是以下行导致FusionLog中的问题:

WRN: 比较程序集名称的结果导致不匹配: PUBLIC KEY TOKEN ERR: 失败以安装程序集 (hr = 0x80131040)。 探测已终止

完整的 FusionLog:

=== 预绑定状态信息 === LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821(完全指定)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: 此绑定在默认加载上下文中启动。LOG: 使用应用程序配置文件: F:\Cab Management System\CMS-Localized\CMS-Code\WebServices\CMSAPI\web.configLOG: 使用主机配置文件: C:\Users\Dell\Documents\IISExpress\config\aspnet.configLOG: 从 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config使用机器配置文件。LOG: 在应用程序配置文件中找到重定向: 1.2.10.0 重定向到 2.0.8.0。LOG: Post-policy 引用: log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821 LOG: 尝试下载新的 URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/864fb64d/ad78f51e/log4net.DLL。LOG: 尝试下载新的 URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/864fb64d/ad78f51e/log4net/log4net.DLL。LOG: 尝试下载新的 URL file:///F:/Cab Management System/CMS-Localized/CMS-Code/WebServices/CMSAPI/bin/log4net.DLL。WRN: 比较程序集名称时出现不匹配: PUBLIC KEY TOKENERR: 无法完成程序集的安装 (hr = 0x80131040)。探测已终止。在com.paypal.sdk.profiles.BaseAPIProfile处出现错误,在PayPalLibrary.PayPalPayment.SetPaymentProfile中设置了支付配置文件,具体路径为F:\path\Classes\PayPalPayment.cs:line 34,在API.ServiceBLL.DoCreditCardPayment中进行信用卡付款操作,具体路径为F:\Path\ServiceBLL.cs:line 2907。根据评论区Ciprian Lipan的建议,在.csproj文件中找到PublicKeyToken并在web.config中进行替换后,只剩下异常信息,内部异常已经消失。以下是.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>

异常

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)

然而,我已经在配置文件中使用新的令牌替换了旧的令牌。

FusionLog

=== 绑定前状态信息 === LOG: 显示名称 = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821 (完全指定) LOG: 应用程序基础目录 = file:///F:/Path/API/ LOG: 初始 私有路径 = F:\path\API\bin 调用程序集 : paypal_base, Version=4.4.55.0, Culture=neutral, PublicKeyToken=b37401294aaf5617. === LOG: 此绑定在默认加载上下文中开始。 LOG: 使用应用程序配置文件: F:\path\API\web.config LOG: 使用 主机配置文件: C:\Users\me\Documents\IISExpress\config\aspnet.config LOG: 使用 位于 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config 的机器配置文件。 LOG: 后策略引用: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821 LOG: 尝试 下载新 URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/864fb64d/ad78f51e/log4net.DLL。 LOG: 尝试 下载新 URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/864fb64d/ad78f51e/log4net/log4net.DLL。 LOG: 尝试下载新 URL file:///F:/path/API/bin/log4net.DLL。WRN: 比较程序集名称结果不匹配: 主版本 ERR: 无法完成程序集设置 (hr = 0x80131040)。探测终止。


当您使用绑定重定向时,应始终指向最新版本 <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />看看这是否有效。此外,请确保在您的入口项目中,您拥有此版本的DLL。 - Catalin
@RaraituL 抱歉,这个没有运气。同样的异常。 - Abdul
请检查您的.csproj文件中的引用。它是否指向正确的dll文件(log4net.dll的路径是否正确)? - Ciprian Lipan
如果你指的是这个 <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> 我可以看到不同的 PublicKeyToken - Abdul
@CiprianLipan 请查看更新。 - Abdul
显示剩余15条评论
2个回答

6

Apache决定更改他们的公钥,烦人!这里有一个类似的帖子,解决方案在这里

或者你可以降级到旧的1.2.10.0版本并使用旧的公钥标记。nuget log4net 1.2.10.0


我正在使用IIS,这有关系吗? - Abdul
不,Apache 是 log4net 的创建者,所以我不是在谈论你使用的托管服务。 - Larry Dukek

0
如果这对某人有所帮助的话,
我在使用log4net版本2.0.15时遇到了类似的问题,与log4net.ext.json版本2.0.10.1一起使用。我将log4net.ext.json降级到2.0.9.1,问题就解决了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接