I've created a MVC 4 Web API Application inside my solution, but I'm getting 2 errors right now and I need some help.
'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?)
This error occurs on the following code
File: WebApiConfig.cs (at App_Start folder)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Another one, is in the Global.asax
'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure'
File: Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.WebHost;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
UPDATE
After installing via Nuget the WebAPI WebHost (suggestion of @sa_ddam213) it resolves some problems, but now a got this error when run my application
Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference
Web.config file has the assembly
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0"/>
</dependentAssembly>
Microsoft.AspNet.WebApi.WebHost
pretty sure you can just nugetInstall-Package Microsoft.AspNet.WebApi.WebHost