0

I am having troubles adding web-api 2 to my existing projects due to the inability to reference System.Net.Http.HttpMessageHandler

Relevent code below

global.asax

<%@ Application Language="C#" Inherits="GlobalAsax" %>

global.asax.cs

using System.Web.Http;
using System.Web.Routing;
/// <summary>
/// Summary description for Global
/// </summary>
/// 
public class GlobalAsax
{
    public GlobalAsax()
    {
    }
    void Application_Start(object sender, EventArgs e)
    {

        // Code that runs on application startup
        RouteTable.Routes.MapHttpRoute(

            name: "Email",

            routeTemplate: "api/{controller}/{id}",

            defaults: new { id = System.Web.Http.RouteParameter.Optional }

            );
    }

Using this setup i get the following error Visual Studio 2017\WebSites\FSWeb\App_Code\Global.asax.cs(23,9): error CS0012: The type 'System.Net.Http.HttpMessageHandler' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Doing my own research on this issue, i see that the assimbly must be added to the web.config in the compilation area, however my web.config alreadythat line, so i'm not sure why it won't compile

Web.config

<compilation debug="true" targetFramework="4.0">
      <assemblies>
          ........
          <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
</compilation>

Does anyone have any ideas what i step i am missing in order to compile with web api?

I will link the resources i have already found and attempted (which failed) below.

https://www.c-sharpcorner.com/UploadFile/dacca2/implement-web-api-in-existing-web-form-application/

Where is the Global.asax.cs file? (used to get the namespace into the global asax in a website project)

The type 'HttpRequestMessage' is defined in an assembly that is not referenced

HttpResponseMessage not working in Web Api (.NET 4.5)

2
  • Have you tried deleting the System.Net.Http reference and adding System.Net.Httpusing nuget package manager? Commented Dec 30, 2018 at 20:30
  • Sorry about the delayed response, Github did not notify me i had a comment for some reason. i had indeed tried to remove and re-add using nuget. That approach did not work for my case. For this specific issue I ended up reverting to an approach without web-api for now. Commented Jan 10, 2019 at 15:44

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.