System.Net.Http.Formatting的nuget版本冲突问题

 

已经添加了nuget Microsoft.AspNet.WebApi.Client

调用System.Net.Http.HttpClient.PostAsJsonAsync的时候报如下的错误:

Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

 

怎么回事那?

【分析】

查看了主网站的项目文件(.csproj)和DLL的项目文件(.csproj),发现两个项目中引用的.cspro版本不一致。

DLL的项目的引用如下:

<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

<SpecificVersion>False</SpecificVersion>

<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>

</Reference>

 

主项目中的引用如下:

<Reference Include="System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

<SpecificVersion>False</SpecificVersion>

<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll</HintPath>

</Reference>

 

这样就导致实际放到bin目录下的是5.2.2版本,这样DLL 项目就找不到5.2.3版本了。

 

【解决方法】

这几个地方5.2.2版本都要改成5.2.3.

  1. 主项目文件。

<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

<SpecificVersion>False</SpecificVersion>

<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll</HintPath>

</Reference>

  1. 主项目的引用,可能默认引用到了是系统的.net framework目录下的,要改成和DLL项目中一样的路径(也就是nuget中的路径)
  2. 主项目的web.config。

<dependentAssembly>

<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.3.0" />

</dependentAssembly>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值