Jam*_*mer 3 .net c# asp.net nuget asp.net-mvc-4
我刚刚开始抛出这个奇怪的异常,我完全不确定如何前进并解决它.
[A]System.Net.Http.Headers.MediaTypeHeaderValue cannot be cast to [B]System.Net.Http.Headers.MediaTypeHeaderValue.
Type A originates from 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'.
Type B originates from 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_2.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'
在此行的客户端上的WebAPI中发生错误:
var data = responsecontent.ReadAsAsync<List<MyClass>>().Result;
我已经在托管API客户端的网站和API解决方案中检查了每个对此DLL的引用.它们都引用了完全相同的dll:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll
我注意到API使用的是较新版本的System.Net.Http.Formatting
dll,但它只是次要的版本增量,并且它被更新为依赖于其他东西,所以我厌恶尝试"降级"并在此过程中创建另一个问题.
API System.Net.Http.Formatting是:
\Microsoft.AspNet.WebApi.Client.4.1.0-alpha-121112\lib\net40\System.Net.Http.Formatting.dll
网站System.Net.Http.Formatting是:
\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll
我确实发现,即使在下拉菜单中选择了"仅稳定",NuGet也会将alpha软件包作为依赖项下载.
Jam*_*mer 11
事实证明,某些NuGet更新出了问题,并且在客户端的web.config文件中创建了一个流氓绑定重定向.
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
将其更改回以前的版本:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
修复了客户端的一切.
归档时间: |
|
查看次数: |
3827 次 |
最近记录: |