The type or namespace IHttpActionResult not found

asp.net MvcNamespaces

asp.net Mvc Problem Overview


This is the first time I am creating a Web API application in ASP.NET MVC4. I opened a new Web API project and added a new controller named 'Product'. The function given below shows an error namespace not found.

public IHttpActionResult GetProduct(int id) 
{
    var product = products.FirstOrDefault((p) => p.Id == id);
    if (product == null)
    {
        return NotFound();
    }
    return Ok(product);
 }

Can anyone help me to solve this problem?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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

Solution 2 - asp.net Mvc

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

Solution 3 - asp.net Mvc

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!

Solution 4 - asp.net Mvc

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

Solution 5 - asp.net Mvc

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.

Solution 6 - asp.net Mvc

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/

Solution 7 - asp.net Mvc

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/

Solution 8 - asp.net Mvc

FYI I was getting the same issue when using .NET Core 3.1.

The solution was to use IActionResult instead of IHttpActionResult.

Solution 9 - asp.net Mvc

Using NuGet to install the Web API2 Core lib. dll. You may have to update Nuget before install ing Web API2 because some components in API2 not compatible with old Nuget package. I had done this way and problem was resolved.

Solution 10 - asp.net Mvc

In my case after updating System.Web.Http to version 5.0.0.0, I needed to restart the IDE in order to fix this problem.

Solution 11 - asp.net Mvc

This issue seems to happen in 2 recent projects I have started using visual studio 2015. Project is an ASP.Net MVC 5 website with mvc and web api components. After running the updates and cleaning up unwanted nuget packages I copied some boilerplate code from another similar project and had the same issue with IHttpActionResult and RouteAttribute not found.

The problem was due to the incorrect Version of the System.Web.Http.dll referenced in the project references. By default the system GAC version of the assembly is used.

To fix this, simply remove this reference and add a reference to the same assembly in the Nuget package folder: [project folder]\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll

You should check that your have updated to the required version of Microsoft.AspNet.WebApi.Core nuget package first.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBPXView Question on Stackoverflow
Solution 1 - asp.net MvcChandra MallaView Answer on Stackoverflow
Solution 2 - asp.net Mvcuser3392357View Answer on Stackoverflow
Solution 3 - asp.net MvcCattoView Answer on Stackoverflow
Solution 4 - asp.net MvckasimView Answer on Stackoverflow
Solution 5 - asp.net MvcKuntal GhoshView Answer on Stackoverflow
Solution 6 - asp.net Mvcz0mbi3View Answer on Stackoverflow
Solution 7 - asp.net MvcMatthew KView Answer on Stackoverflow
Solution 8 - asp.net MvcOliver PearmainView Answer on Stackoverflow
Solution 9 - asp.net MvcanhdktkView Answer on Stackoverflow
Solution 10 - asp.net Mvcmouse m.d.View Answer on Stackoverflow
Solution 11 - asp.net MvckasView Answer on Stackoverflow