ChatGPT解决这个技术问题 Extra ChatGPT

How to get 'System.Web.Http, Version=5.2.3.0?

I just created an MVC5 project and added several packages from nuget, but then when I compiled the project, i got this error. It seems one of the packages really depends on system.web.http version 5.2.3.0, which i couldn't find anywhere. I just wonder how to get the latest version of system.web.http ?

Error   2   Assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
d:\Backup 2014-12-25\Website-Projects\www.ptsol.com.au\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll

R
Roman Patutin

In Package Manager Console

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3


I did but still giving me the same error
PM> install-package microsoft.aspnet.webapi.core -version 5.2.3 Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.3)'. Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'. 'Microsoft.AspNet.WebApi.Core 5.2.3' already installed. www.ptsol.com.au already has a reference to 'Microsoft.AspNet.WebApi.Core 5.2.3'.
@JohnHadikusumo do this for all of your projects. It appears you have a dependent project with an older version.
Yes, this will work. Carefully read your Web.config and your packages.config both before and after you run this command and you'll see what changed.
Solved my problem.
I had to use Install-Package Microsoft.AspNet.WebApi.Client -Version 5.2.7 instead (.Client instead of .Core). I had .Core 5.2.7 already, but I was still getting the error. nuget.org/packages/Microsoft.AspNet.WebApi.Client
B
Bracher

One way to fix it is by modifying the assembly redirect in the web.config file.

Modify the following:

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

to

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="4.0.0.0" />
</dependentAssembly>

So the oldVersion attribute should change from "...-4.0.0.0" to "...-5.2.3.0".


This worked for me. We had the bindingRedirect setup as <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> but changed it to use 4.0.0.0. Still doesn't makes sense to me, because should be using the NuGet package DLL and not the GAC version, but hey, it worked... so thanks!
J
James Skemp

I did Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3 but it still did not work. Then looked in my project bin folder and saw that it still had the old System.Web.Mvc file.

So I manually copied the newer file from the package to the bin folder. Then I was up and running again.


V
Vitali Siamenau

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3

Then in the project Add Reference -> Browse. Push the browse button and go to the C:\Users\UserName\Documents\Visual Studio 2015\Projects\ProjectName\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45 and add the needed .dll file


D
Douglas Wiley

The packages you installed introduced dependencies to version 5.2.3.0 dll's as user Bracher showed above. Microsoft.AspNet.WebApi.Cors is an example package. The path I take is to update the MVC project proir to any package installs:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3

https://www.nuget.org/packages/microsoft.aspnet.mvc


J
James Skemp

Uninstalling and re-installing the NuGet package worked for me.

Remove any old reference from the project.

Execute this in the Package Manager Console:

UnInstall-Package Microsoft.AspNet.WebApi.Core -version 5.2.3 Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3


Just this one solved my problem. I've done so much and win-action was so simple.
R
Rixant

install this in your nuget package manager

Install-Package Microsoft.AspNet.WebApi.WebHost -Version 5.2.7

and paste

using System.Web.Http;

This should work