我开始在C#项目中使用HttpClient.GetAsync()。无论何时调用此方法,它都会爆炸,无法找到Newtonsoft.Json。
为了获得该方法,我安装了Microsoft.AspNet.WebApi.Client nuget软件包,版本5.2.3。这列出了对Newtonsoft.Json,v 6或更高版本的依赖。已安装8.0.3版。
我做错了什么? nuget包应该管理它自己的依赖项?为什么nuget为系统DLL?完整的错误如下......
System.IO.FileLoadException was unhandled by user code
FileName=Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
HResult=-2146234304
Message=Could not load file or assembly 'Newtonsoft.Json, Version=6.0.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)
Source=System.Net.Http.Formatting
StackTrace:
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Net.Http.HttpContentExtensions.get_DefaultMediaTypeFormatterCollection()
at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content)
at Dimo.Notilus.Interfaces.Expense.HubHacienda.<>c__DisplayClass0_0.<GetFromHub>b__0(Task`1 task) in C:\NotilusTNE\Sources\NotilusWeb\Agile\Dev\NotilusWeb\Dimo.Notilus.Interfaces\Expense\HubHacienda.cs:line 22
at System.Threading.Tasks.Task.Execute()
InnerException:
答案 0 :(得分:1)
尝试将程序集绑定重定向添加到app / web.config
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<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>
</assemblyBinding>
</runtime>
</configuration>