我开始在c#project中使用httpclient.getAsync()。每当调用此方法时,它会炸毁,无法找到newtonsoft.json。
要获取方法,我安装了Microsoft.aspnet.webapi.client Nuget软件包,版本5.2.3。这列出了对newtonsoft.json,v 6或更高的依赖性。安装了8.0.3版。
我在做什么错?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 [HKLMSoftwareMicrosoftFusion!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 [HKLMSoftwareMicrosoftFusion!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:NotilusTNESourcesNotilusWebAgileDevNotilusWebDimo.Notilus.InterfacesExpenseHubHacienda.cs:line 22
at System.Threading.Tasks.Task.Execute()
InnerException:
尝试将汇编绑定重定向添加到您的应用/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>