尽管具有程序集重定向和加载正确的版本,但程序集不匹配 [英] Assembly mismatch despite having assembly redirect and loading correct version

查看:25
本文介绍了尽管具有程序集重定向和加载正确的版本,但程序集不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My console app uses System.Net.Http.Formatting v5.1.0.0 that depends on Newtonsoft.Json v4.5.0.0. My app however includes v6.0.0.0 of Newtonsoft.Json (for other reasons).

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

To make System.Net.Http.Formatting use the new Newtonsoft.Json version I added an assembly redirect to the 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)

融合日志显示正确的程序集已加载,但由于不匹配而失败:

The fusion log shows that the correct assembly is loaded but it fails because of mismatch:

*** 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:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable  D:ConsoleApplication1inDebugConsoleApplication1.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:ConsoleApplication1inDebugConsoleApplication1.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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:ConsoleApplication1inDebugNewtonsoft.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.

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

What can I do to resolve this mismatch? Thanks in advance.

解决方案

重定向没有任何问题.唯一的线索是它以某种方式甚至没有被应用,尽管看起来一切都按预期工作(请注意,日志甚至显示加载了正确的配置文件).问题是在 assemblyBinding 部分中有另一个程序集问题的声明:

There was nothing wrong with the redirect. The only clue was that it somehow didn't even get applied, although seemingly everything worked as expected (note that the log even shows that the correct config file is loaded). The issue was that there was this declaration in the assemblyBinding section for another assembly issue:

<qualifyAssembly partialName="log4net" fullName="log4net, 1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />

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

This line solved that other issue but somehow broke the Json redirect. I don't know why: the qualifyAssembly declaration is supposedly correct too.

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

Nevertheless removing this declaration made the assembly redirect work...

推荐答案

没有证据表明您的 有效.你应该看到:

There is no evidence that your <bindingRedirect> is in effect. You should see:

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:ConsoleApplication1inDebugConsoleApplication1.exe.Config.奇怪的驱动器号.当心一个项目已经有一个 App.config 项目项并且你添加了 App1.config.类似的东西.

There are no breadcrumbs in your question, but whatever you edited appeared to not have been D:ConsoleApplication1inDebugConsoleApplication1.exe.Config. Odd drive letter. Beware of a project already having an App.config project item and you adding App1.config. Something like that.

这篇关于尽管具有程序集重定向和加载正确的版本,但程序集不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆