我发现有几个线程与这个问题相关,但没有一个解决了我的问题。
我之前在我的 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<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