程序集引用的位置在哪里?

时间:2018-08-06 19:33:41

标签: c# .net-assembly fusion

我有一个Newtonsoft的FileLoadException,当我安装11.0.2.0时正在寻找版本6.0.0.0。 packages.config和web.config一样被设置为寻找较新的版本。引用中的.dll版本为11,解决方案外部的Framework文件夹中的临时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.

1 个答案:

答案 0 :(得分:0)

该解决方案可能对大多数遇到装配引用问题的人没有用,但是这是我对有类似问题的千分之一工作的人所要做的。

内部版本正确地从调用程序集(System.Net.Http.Formatting)重定向6.0.0.0版本到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中的其他内容导致生成的版本在运行时中断。

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