The type or namespace IHttpActionResult not found

前端 未结 11 1996
小鲜肉
小鲜肉 2021-01-31 14:04

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

相关标签:
11条回答
  • 2021-01-31 14:12

    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!

    0 讨论(0)
  • 2021-01-31 14:16

    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

    0 讨论(0)
  • 2021-01-31 14:16

    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.

    0 讨论(0)
  • 2021-01-31 14:20

    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.

    0 讨论(0)
  • 2021-01-31 14:24

    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

    0 讨论(0)
  • 2021-01-31 14:25

    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/

    0 讨论(0)
提交回复
热议问题