System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter Error

烂漫一生 提交于 2019-12-06 05:12:00

问题


I am trying to upgrade my asp.net project from Mvc 4 to 5. I followed these instructions:

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

When I want to compile my project I am getting following error :

Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly 'System.Net.Http.Formatting, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

If I add the reference to System.Net.Http.Formatting Version=4.0.0.0 then I am getting this error:

Assembly 'System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Net.Http.Formatting, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Can anyone help me?


回答1:


I presume the unspoken part of your question (which @Adriano clearly did not infer) is that you don't see version 5.2.0.0 in the list when you go to add a reference, you see only version 4.0.0.0, right?

If so, the issue is probably your NuGet packages, which means you have an additional package you need to upgrade. In my case it was Microsoft.AspNet.WebApi.Client (apparently System.Net.Http.Formatting is in that assembly…?!?), which was upgraded in one of the projects in my solution but not the other. In your case, it looks like perhaps you need to install the upgrade of that particular package, and/or it was missed when you upgraded the other MVC packages.



来源:https://stackoverflow.com/questions/25282558/system-net-http-formatting-formurlencodedmediatypeformatter-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!