Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API error after upgrading to Visual Studio 2012 RC: Method not found: 'Void System.Net.Http.Headers.HttpHeaders.AddWithoutValidation

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?

like image 477
Peter Moberg Avatar asked Jun 02 '12 13:06

Peter Moberg


2 Answers

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

like image 117
Henrik Frystyk Nielsen Avatar answered Sep 25 '22 09:09

Henrik Frystyk Nielsen


Solution to this and other RC-related issues right here.

like image 28
JSancho Avatar answered Sep 23 '22 09:09

JSancho