【问题标题】:Where is the location of an Assembly reference?装配参考的位置在哪里?
【发布时间】:2018-08-06 19:33:40
【问题描述】:

我有一个 Newtonsoft 的 FileLoadException,当我安装 11.0.2.0 时正在寻找版本 6.0.0.0。 packages.config 设置为查找较新的版本,web.config 也是如此。参考中的 .dll 版本是 11,我的解决方案之外的框架文件夹中的临时 ASP 文件也是如此。我已经尝试强制卸载 newtonsoft 并在包管理器控制台中安装最新版本。

在代码内外,我找不到任何定义版本 6.0.0.0 的地方。这是在哪里设置的?

这是融合日志(你可以看到它正在尽一切可能在失败之前获得匹配):

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed(Fully-specified)
LOG: Appbase = file:///C:/Repos/MyProjectPath/
LOG: Initial PrivatePath = C:\Repos\MyProjectPath\bin
Calling assembly : System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Repos\MyProjectPath\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyProjectFolder/20c630f1/c09fb4a6/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyProjectFolder/20c630f1/c09fb4a6/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Repos/MyProjectPath/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

【问题讨论】:

  • 您是否尝试过在您的 app/web.config 中使用 <bindingRedirect/> 元素?或者,您是否看过这是否是这些元素之一的结果?
  • 对它的任何引用是否将Specific Version 设置为True(选择引用并在“属性”窗口中查看)。
  • 对 6.0 版的引用可能是间接的。请求程序集是 System.Net.Http.Formatting。要么你引用这个程序集,要么你正在使用的东西是。解决方案是在从 6.0 映射到 11.0 的配置文件中设置程序集绑定重定向。通常这是在automatically 完成的,因此您可能需要检查您的项目和/或 IDE 设置。
  • web.config 文件有一个绑定重定向,指定 oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0"。 @Richardissimo,具体版本设置为true。
  • 跟踪表明这不起作用,它仍在寻找 6.0.0.0。只需确保您编辑了正确的 web.config 文件并在您的问题中显示其完整内容。

标签: c# .net-assembly fusion


【解决方案1】:

该解决方案可能对大多数遇到装配参考问题的人没有用,但对于千分之一的有类似问题的人来说,这是我必须做的。

构建将版本 6.0.0.0 引用从调用程序集 (System.Net.Http.Formatting) 正确重定向到 11.0.0.0,如构建日志的详细输出所示:

Unified primary reference "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". (TaskId:108)
7>      Using this version instead of original version "6.0.0.0" in "C:\Repos\MySolutionFolder\NugetPackages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll" because of a binding redirect entry in the file "Web.config". (TaskId:108)
7>      Using this version instead of original version "6.0.0.0" in "C:\Repos\MySolutionFolder\NugetPackages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll" because of a binding redirect entry in the file "Web.config". (TaskId:108)
7>      Using this version instead of original version "6.0.0.0" in "C:\Repos\MyReferencedProjectPath\bin\Debug\MyLibrary.dll" because of a binding redirect entry in the file "Web.config". (TaskId:108)
7>      Resolved file path is "C:\Repos\MySolutionFolder\NugetPackages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll". (TaskId:108)

但是,即使 web.config bindingRedirect 是正确的,在 web.config 的应用程序设置中,如果没有在最终构建中删除,将阻止重定向在运行时工作。以下是 web.config 中的违规元素:

<?ap-config target="add[@key='Environment']/@value"
  value="{@environment}"
  when="true()" ?>

我的特定解决方案涉及构建后事件脚本,该脚本会在将其放入我的解决方案中每个 Web 项目的构建输出文件夹之前从文件中删除该行。您的特定应用可能需要不同的解决方案,但关键是即使构建输出声称程序集引用是通过重定向找到的,web.config 中的其他内容也会导致构建版本在运行时中断。

我不知道如何进行更深入的调试来跟踪此问题,因此您只需要知道即使成功的构建日志也不能说明全部情况。

【讨论】:

    猜你喜欢
    • 2018-10-31
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    相关资源
    最近更新 更多