After upgrading to Visual Studio 2012 I can no longer access any of my ApiControllers, the following error is thrown:
Server Error in '/' Application. Method not found: 'Void System.Net.Http.Headers.HttpHeaders.AddWithoutValidation(System.String, System.Collections.Generic.IEnumerable`1<System.String>)'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: Method not found: 'Void System.Net.Http.Headers.HttpHeaders.AddWithoutValidation(System.String, System.Collections.Generic.IEnumerable`1<System.String>)'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [MissingMethodException: Method not found: 'Void System.Net.Http.Headers.HttpHeaders.AddWithoutValidation(System.String, System.Collections.Generic.IEnumerable`1<System.String>)'.] System.Web.Http.WebHost.HttpControllerHandler.AddHeaderToHttpRequestMessage(HttpRequestMessage httpRequestMessage, String headerName, String[] headerValues) +0 System.Web.Http.WebHost.HttpControllerHandler.ConvertRequest(HttpContextBase httpContextBase) +248 System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, Object state) +79 System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +268 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17626
Anyone knows how to fix this?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You have a reference to an old version of System.Net.Http in your project. To fix this, go under “References” in your project, delete System.Net.Http, and add the version that comes with .NET 4.5 instead. That should do it.
Henrik
Method 2
Solution to this and other RC-related issues right here.
Method 3
step 1
Remove the below references from your project:
System.Net.Http, System.Web.Http, System.Web.Http.WebHost , System.Web.Http.Common & System.Net.Http.Formatting
step 2
Add the above refefrences (except the System.Web.Http.Common & System.Net.Http.Formatting) from Below location
- C:Program Files (x86)Microsoft ASP.NETASP.NET MVC 4PackagesMicrosoft.AspNet.WebApi.Core.4.0.20505.0libnet40
- C:Program Files (x86)Microsoft ASP.NETASP.NET MVC 4PackagesMicrosoft.AspNet.WebApi.WebHost.4.0.20505.0libnet40
- C:Program Files (x86)Microsoft ASP.NETASP.NET MVC 4PackagesMicrosoft.Net.Http.2.0.20505.0libnet40
and add one more new dll Newtonsoft.Json.dll from
- C:Program Files (x86)Microsoft ASP.NETASP.NET MVC 4PackagesNewtonsoft.Json.4.5.1libnet40
Method 4
This fixed it for me.
http://forums.asp.net/t/1809919.aspx/1
Method not found: ‘Void System.Net.Http.Headers.HttpHeaders.AddWithoutValidation(System.String, System.Collections.Generic.IEnumerable`1)’.
I resolved it with the following steps. Not sure if all of them are required, but it worked.
In NuGet Package Manager, uninstalled the Web.API Beta package.
Added references to System.Net.Http, System.Web.Http, & System.Web.Http.WebHost (these were removed by the previous step).
Installed Json.Net via NuGet.
As an addition, if your project is targeting the 4.0 version of the framework, you must include the new Microsoft ASP.Net Web API set of packages from NUGET, to get a green light for your build. Json.Net is a dependency for these new packages, so you need not install it separate.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0