Newtonsoft.Json装配冲突 - DLL地狱

时间:2016-05-17 20:09:20

标签: asp.net json.net

尝试升级到Newtonsoft.Json版本8,我不断加载"无法加载文件或程序集' Newtonsoft.Json,Version = 6.0.0.0。 Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。"

我的项目(或我的解决方案中的任何项目)都不再引用版本6了。我已经浏览了互联网和堆栈交换,但没有一个建议有效。我在web.config文件中列出了这个:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>

项目在我的本地环境中加载正常。在我推送到Main并将其部署到QA之后,它在QA中爆炸。我把Main拉到我的本地机器上,它崩溃了同样的错误。

我非常沮丧。如果你有任何建议,而不是互联网上已经提到的建议,我很高兴听到它。

我尝试过Fusion(没有帮助)。

编辑:

Fusion错误日志

*** Assembly Binder Log Entry  (5/17/2016 @ 1:48:49 PM) ***

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  C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/
LOG: Initial PrivatePath = C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: AppName = fd029416
Calling assembly : MY.MyApp.Services.REST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/bin/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin\Newtonsoft.Json.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=8.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: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

*** Assembly Binder Log Entry  (5/17/2016 @ 1:48:49 PM) ***

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  C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/
LOG: Initial PrivatePath = C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: AppName = fd029416
Calling assembly : MY.MyApp.Services.REST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/bin/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin\Newtonsoft.Json.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=8.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: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

编辑:

我浏览了解决方案中的每个项目文件,他们都通过以下方式引用了Newtonsoft.Json:

<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>

2 个答案:

答案 0 :(得分:0)

嗯,不是我要找的答案,但它解决了我的问题。我将Newtonsoft.Json推回到版本6.这消除了运行时错误。我真的无法浪费更多的时间来解决一个不应该成为问题的问题。

在进行所有故障排除时,我发现许多第三方依赖项依赖于Newtonsoft.Json(各种不同的版本)。 WebApi 2.2需要版本6.其他人需要版本5.

这种版本要求的混合是bindingRedirect创建的全部原因。所以我的问题实际上是bindingRedirect没有按设计工作。

答案 1 :(得分:0)

我遇到了同样的问题:一切都在开发中进行,并且在部署到prepro / production服务器时出现此错误。我的web.config已经具有bindingRedirect。

在将所有软件包更新为NuGet中的最新版本并重新部署之后,该问题得到了神奇的解决。显然,它使用的是VisualStudio附带的软件包,并对其进行更新以某种方式解决了该问题。

相关问题