WebAPI detected link error when I have assembly

I created the MVC 4 Web API application inside my solution, but now I have 2 errors and I need help.

'System.Web.Http.HttpConfiguration' does not contain a definition for "MapHttpAttributeRoutes" and the extension method "MapHttpAttributeRoutes" takes the first argument of the type You can find "System.Web.Http.HttpConfiguration" (you do not see using the directive or the link to the assembly?)

This error occurs in the following code

File: WebApiConfig.cs (in the 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 } ); } } 

The other is in 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); } } 

enter image description here

UPDATE

After installing via Nuget WebAPI WebHost (@ sa_ddam213 suggestion), it fixes some problems, but now this error occurs when my application starts

Failed to load file or assembly "System.Net.Http" or one of the dependencies. Installed assembly manifest definition does not map assembly reference

The web.config file has an 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> 
+48
c # asp.net-web-api asp.net-mvc-4
Aug 07 '14 at 11:31
source share
7 answers

I uninstall some nuget packages in my project, including MVC, and reinstall everything. It is resolved. Thank you all for your help.

+7
Jan 04 '15 at 22:53
source share

Forcing reinstallation of WebAPI can complete the task:

  update-package microsoft.aspnet.webapi -reinstall 
+95
Feb 06 '15 at 12:33
source share

I did:

 get-project <project_name> | uninstall-Package Microsoft.AspNet.WebApi.WebHost -force 

Then reinstall (with a specific version compatible with versions in other projects)

 get-project <project_name> | install-Package Microsoft.AspNet.WebApi.WebHost -Version 5.2.2 

This solved the problem for me.

+12
Apr 20 '15 at 10:35
source share

Update NuGet Packages. Worked for me.

+6
Jan 21 '15 at 8:35
source share

Try updating your packages by running the following command on the nugetmanager console

 update-package microsoft.aspnet.webapi.webhost -reinstall 
+5
Feb 03 '16 at 11:28
source share

In particular, for me, I loaded someone from TFS into a solution for work and received an error

 System.Web.Http.HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' 

I was ABOUT US , continuing to reinstall the web api, but I know that past experience is that the dependency chain of the order in which you set the elements may turn out to be a little drama.

JSON hits or skips, because sometimes I saw the updated JSON power and uninstall a new version of another package and install an older version because she thought she knew best.

For me, UPDATE JSON via nuget is all I had to do.

+1
Dec 21 '15 at 18:36
source share

1) Check the solution folder packages \ Microsoft.AspNet.WebApi.Client.5.2.3 \ lib \ net45 has System.Web.Http.dll or not. He must be there. If it is not available, copy it from any other folder of the running project packages. 2) Remove the link from System.Web.Http.dll from your project. 3) Add a new link, pointing to the new .dll, which is intended for the packages \ Microsoft.AspNet.WebApi.Client.5.2.3 \ lib \ net45 \ System.Web.Http.dll

0
Aug 04 '17 at 6:17
source share



All Articles