使用httpclient测试webapi的时候客户端报错:
{"未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)":"Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}
问题是由于System.Net.Http.Formatting和Json.NET版本冲突,在app.config里对Json.NET的版本重定向一下就好了。
<?xml version="1.0" encoding="utf-8" ?><configuration> ???<startup> ????????<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> ???</startup> ?<runtime> ???<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> ?????<dependentAssembly> ???????<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/> ???????<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> ?????</dependentAssembly> ???</assemblyBinding> ?</runtime></configuration>