问题
I am getting below error after upgrade my project from MVC4 to MVC5. I followed How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2
Assembly 'WebServices.WebApi.External, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
How to solve this issue?
回答1:
I had a similar problem, it was due to me using the
_bin_deployableAssemblies
This folder had the System.Web.Http in it at version 4. I deleted this folder and it worked
回答2:
I also follow that article without full success at start but
To fix this "simple" create new web mvc project and save it then open web.config, web.config from views, packages.config, and .csproj in notepad
then open your project and look at difference in entry for version numbers of files e.g. in packages you should see
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
but you can have
<package id="Microsoft.AspNet.Mvc" version="4.x.x.x" targetFramework="net40" />
in web.config
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
but you can have
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
in .csproj
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
but you can have
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
</Reference>
replace all with newer values
after that do Ctrl+Shift+B and in nuget console update all packages by comand Update-Package
for me this work finally
回答3:
I solved this by installing the System.Web.Http.WebHost. You can install by using nuget and search for WebHost. This is the exact link https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/5.1.0
you can also install it from the Package Manager Console: PM> Install-Package Microsoft.AspNet.WebApi.WebHost
回答4:
You should check all references of WebServices.WebApi.External project. One of them may still use System.Web.Http version 4. Or, try binding it explicitly in web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
回答5:
Had the same problem. Solved by uninstalling the old AttributeRouting package with Nuget. Of course, it is not needed anymore.
This was in a unit testing project, too.
回答6:
In my case I just removed the troublesome binding from the Web.config file, that solved the issue.
Backup you web.config, then simply erase dependentAssembly
element containing an assemblyIdentity
element with the name System.Web.Http
.
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
It worked for me instantly.
来源:https://stackoverflow.com/questions/19503354/errorupgrade-mvc4-to-mvc5-in-vs2012