Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace IHttpActionResult not found

People also ask

What is IHttpActionResult namespace?

The IHttpActionResult interface is contained in the System. Web. Http namespace and creates an instance of HttpResponseMessage asynchronously. The IHttpActionResult comprises a collection of custom in-built responses that include: Ok, BadRequest, Exception, Conflict, Redirect, NotFound, and Unauthorized.

How do I return IHttpActionResult in Web API?

If a controller action returns an IHttpActionResult, Web API calls the ExecuteAsync method to create an HttpResponseMessage. Then it converts the HttpResponseMessage into an HTTP response message. More often, you use the IHttpActionResult implementations defined in the System. Web.

What is the difference between IActionResult and IHttpActionResult?

What is the difference between IHttpActionResult and IActionresult ? "IActionResult is the new abstraction that should be used in your actions. Since Web API and MVC frameworks have been unified in ASP.NET Core, various IActionResult implementations can handle both traditional API scenarios.".

Which of the following defines a model in Web API?

A model is an object that represents the data in your application. ASP.NET Web API can automatically serialize your model to JSON, XML, or some other format, and then write the serialized data into the body of the HTTP response message.


Since you are using Asp.Net 4.0, IHttpActionResult is not available in Namespace System.Web.Http version 4.0 so you have to update your namespace to version 5.0.0.0. You can Check your namespace version by right click System.Web.Http namespace in references and go to properties. You can update this by Right Clicking on your Solution project->Manage NuGet Packages for Solution-> Search for Asp.Net WebAPI 2 ->Select Asp.Net WebAPI 2 and click Manage. Also you can check if it is available on update tab, if it is available in update tab you can update from there. Once you did that, confirm version by going to properties of System.Web.Http namespace in references.

This works for me and hope will work for you too.

Thanks


I had a similar problem when I checked out a project from my source control.

I had the reference to Microsoft ASP.NET Web API 2 in the project but i still couldn't compile the project.

The solution was to re install the package using the Package Manager Console:

PM> update-Package Microsoft.AspNet.WebApi –reinstall


To resolve the IHttpActionResult reference error add a reference using NuGet to install the Web API2 Core lib. dll

In solution explorer in the references right click and select manage nuget packages. (if not there install nuget)

In the manage NuGet Packages window on the left side click online then in top right search for API 2.1 and install Microsoft ASP.NET Web API 2.1 Core Libraries. (Once installed the install button will change to a green check)

enter image description here

After that the project will reload and when it's build again the IHttpActionResult reference error will be resolved and the project will build successful. Your question was good and helped me. Hope this answer helps!


Check with this link to get the namespace for IHttpActionResult and all.

This package contains everything you need to host ASP.NET Web API on IIS. ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

To install Microsoft ASP.NET Web API 2, run the following command in the Package Manager Console Or Manage NuGet Packages

PM> Install-Package Microsoft.AspNet.WebApi -Version 5.0.0


I had similar problem & re installation will solve this issue. Just go to Tools > NuGet Package Manager > Package Manager Console in Visual Studio 2013 and write down the following :-

PM> update-Package Microsoft.AspNet.WebApi –reinstall

Then, Clean the solution and Build/Rebuild the solution.

Note: In my case, the process explicitly checked out Web.config and packages.config file and also removed the System.Web.Http dll file.


This solution worked for me:
Tools – > Library Package Manager -> Package Manager Console, then type:
Install-Package Microsoft.AspNet.WebApi -Version 5.0.0
update-Package Microsoft.AspNet.WebApi –reinstall
Reference: http://blog.bitlinkit.com/type-namespace-ihttpactionresult-not-found/


The features you are trying to use are part of Web API 2. Since you mentioned you're using MVC 4, I expect you will want to upgrade your references to MVC 5 and Web API 2.

Find out more about these features at http://www.strathweb.com/2013/06/ihttpactionresult-new-way-of-creating-responses-in-asp-net-web-api-2/