1

nenne ich keine HttpConfiguration Erweiterung Methode aufrufen kann:C# - Es kann keine HttpConfiguration Erweiterungsmethoden

using System.Configuration; 
using System.Web.Http; 
... 
     var config = new HttpConfiguration(); 
     config.MapHttpAttributeRoutes(); // <-- error 

Error: '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?)

Ich habe versucht, beide mit System.Web.Http Version 4 und 5, und mit“.NET Framework 4.5 .2 "und" .NET Framework 4 ".

Was fehlt mir?

Reference

+0

Seine adaequat. var config = new System.Web.Http.HttpConfiguration(); config.MapHttpAttributeRoutes(); – sam

+0

@Pietro, stellen Sie sicher, dass Sie einen Verweis auf Assembly System.Web.Http.dll in Ihrem Projekt haben, wo dieser Code ausgeführt wird. Versuchen Sie auch, bin-Ordner zu löschen und dann das Projekt – Nkosi

+0

@ Nkosi neu zu erstellen, ich habe es ausgewählt. Nur ein Zweifel über seine Version. Ich habe: System.Web v. 4.0, System.Web.Http v. 4.0 und System.Web.Http.Owin V. 5.2.3. Ich kann System.Web.Http v. 5.2.3 (um Owin zu entsprechen), aber kein System.Web> 4.0. Könnte das ein Problem sein? – Pietro

Antwort

1

Stellen Sie sicher, einen Verweis auf Assembly System.Web.Http.dll, v5.2.3.0 in Ihrem Projekt haben, wo dieser Code ausgeführt wird. HttpConfigurationExtensions.MapHttpAttributeRoutes wurde ASP.NET Web API 2.2 hinzugefügt, die die oben genannte Version der Assembly erfordert.

+0

Ja, aber ich musste auch 'System.Net.Http.Formatting' auf 5.2.3.0 aufrüsten. – Pietro

0

dieses Problem behoben (streng im Zusammenhang mit this one) in Projekt> Reference Manager festgelegt wird:

für mich
Microsoft.Owin 2.0.2.0 
Owin 1.0.0.0 
System.Net.Http.Formatting 5.2.3.0 
System.Web 4.0.0.0 
System.Web.Http 5.2.3.0 
System.Web.Http.Owin 5.2.3.0 
Verwandte Themen