.net – System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter Error

asp.netasp.net-mvcasp.net-mvc-4asp.net-mvc-5net

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?

Best Answer

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.