gpt4 book ai didi

.net - 尽管具有程序集重定向和加载正确的版本,但程序集不匹配

转载 作者:行者123 更新时间:2023-12-03 23:17:21 25 4
gpt4 key购买 nike

我的控制台应用程序使用 System.Net.Http.Formatting v5.1.0.0,它依赖于 Newtonsoft.Json v4.5.0.0。但是,我的应用程序包含 Newtonsoft.Json 的 v6.0.0.0(出于其他原因)。

为了使 System.Net.Http.Formatting 使用新的 Newtonsoft.Json 版本,我添加了一个程序集重定向到 App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

我仍然收到以下异常:
A first chance exception of type 'System.IO.FileLoadException' occurred in System.Net.Http.Formatting.dll

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

融合日志显示正确的程序集已加载,但由于不匹配而失败:
*** Assembly Binder Log Entry  (2014.08.10. @ 13:13:25) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///D:/ConsoleApplication1/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ConsoleApplication1.exe
Calling assembly : System.Net.Http.Formatting, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/ConsoleApplication1/bin/Debug/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\ConsoleApplication1\bin\Debug\Newtonsoft.Json.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我该怎么做才能解决这种不匹配问题?提前致谢。

解决方案

重定向没有任何问题。唯一的线索是它以某种方式甚至没有得到应用,尽管看起来一切都按预期工作(请注意,日志甚至显示加载了正确的配置文件)。问题是在 assemblyBinding 部分中有另一个程序集问题的声明:
<qualifyAssembly partialName="log4net" fullName="log4net, 1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />

这一行解决了另一个问题,但以某种方式破坏了 Json 重定向。我不知道为什么:qualifyAssembly 声明也应该是正确的。

尽管如此,删除此声明会使程序集重定向工作......

最佳答案

没有证据表明您的 <bindingRedirect>有效。你应该看到:

LOG: Redirect found in application configuration file: 4.5.0.0 redirected to 6.0.0.0.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

您的问题中没有面包屑,但您编辑的任何内容似乎都不是 D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.Config。奇怪的驱动器号。当心一个项目已经有一个 App.config 项目项并且你添加了 App1.config。类似的东西。

关于.net - 尽管具有程序集重定向和加载正确的版本,但程序集不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25228140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com