0
votes

I'm using webapi service into Mvc I had created a reference of Api to mvc but after writing the code I'm getting this error

The type 'System.Web.Http.ApiController' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I also installed this package

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3
1

1 Answers

5
votes

Assembly System.Web.Http is in package Microsoft.AspNet.WebApi.Core. You have to save all files and then run update-package -reinstall System.Web.Http. Script runed after installing will add refernce to this assembly to you project (it will be saved in .csproj). And then save all files again (needed to save project file).

Reference in .csproj file:

<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
</Reference>

E.g. in empty project after Install-Package Microsoft.AspNet.WebApi.Core you will have modification in packages.config and in .csproj files.

If you will close project right after performing install command and choose no to save changes, then you will see this error again.