尝试升级到Newtonsoft.Json版本8,我一直得到"无法加载文件或程序集"Newtonsoft.Json,版本=6.0.0.0。Culture=neutral,PublicKeyToken=30ad4fe6b2a6eed或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。"
我的项目(或解决方案中的任何项目)不再引用版本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(没有帮助)。
编辑:
融合错误日志
*** 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:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable C:WINDOWSSysWOW64inetsrvw3wp.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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTbin
LOG: Dynamic Base = C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filesroot68a38e3a
LOG: Cache Base = C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filesroot68a38e3a
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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTweb.config
LOG: Using host configuration file: C:WindowsMicrosoft.NETFrameworkv4.0.30319aspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTbinNewtonsoft.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:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable C:WINDOWSSysWOW64inetsrvw3wp.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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTbin
LOG: Dynamic Base = C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filesroot68a38e3a
LOG: Cache Base = C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filesroot68a38e3a
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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTweb.config
LOG: Using host configuration file: C:WindowsMicrosoft.NETFrameworkv4.0.30319aspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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:DevelopmentMyAppMainServicesMyAppInternalMY.MyApp.Services.RESTbinNewtonsoft.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>..packagesNewtonsoft.Json.8.0.3libnet45Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
好吧,这不是我想要的答案,但它解决了我的问题。我将Newtonsoft.Json回滚到版本6。这消除了运行时错误。我真的不能浪费更多的时间来解决一个本不应该成为问题的问题。
在进行所有故障排除时,我发现我的许多第三方依赖依赖依赖于Newtonsoft.Json(在各种不同的版本中)。WebApi 2.2需要版本6。其他一些人想要版本5。
这种版本需求的混合是创建bindingRedirect的全部原因。所以我的问题实际上是bindingRedirect没有按设计工作。
我也遇到了同样的问题:一切都在开发中进行,当部署到预印本/生产服务器时,我会遇到这个错误。我的web.config已经具有bindingRedirect。
在NuGet中将所有包更新到最新版本并重新部署后,它神奇地得到了解决。显然,它使用了VisualStudio附带的版本的包,并对其进行了更新,以某种方式解决了问题。