12

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?

4 Answers 4

16

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

2
  • 1
    I was not able to find this methog in the .net 4.0 RC version, but there is a TryAddWithoutValidation Jun 2, 2012 at 21:11
  • I had a similar issue with VS 2017 and Framework 4.7.2 - I can confirm using the Nuget version rather than the GAC version resolved my issue. Jul 12, 2018 at 12:05
3

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

2
  • 1
    Updating all the packages as this post suggests worked for me, but the RC breaks some bundling code I had. Henrik's solution didn't work, which may be ironic given his place on the WebAPI team!
    – Jim Raden
    Jun 4, 2012 at 20:23
  • I see that Henrik Nielsen is now endorsing (?) or at least mentioning this solution on Twitter: twitter.com/frystyk/status/210256371252346882
    – Jim Raden
    Jun 6, 2012 at 6:28
2

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

  1. C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.AspNet.WebApi.Core.4.0.20505.0\lib\net40

  2. C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.AspNet.WebApi.WebHost.4.0.20505.0\lib\net40

  3. C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Net.Http.2.0.20505.0\lib\net40

and add one more new dll Newtonsoft.Json.dll from

  1. C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Newtonsoft.Json.4.5.1\lib\net40
0
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.