I my ASP.NET MVC 4 Project, my Global.asax.cs
page shows the error on
WebApiConfig.Register(GlobalConfiguration.Configuration);
Make sure you have assembly System.Web.Http.WebHost.dll
referenced. This is where GlobalConfiguration is.
I attempted most of the fixes listed above to no avail. I am sure 9 out of 10 are normally resolved by the posts above but for this error, but none of these helped me.
My fix for this error, was that I was renaming my namespace and had two different references to the namespace which in the end caused my issue. Since I wanted to update the namespace with something other than I started with, I ended up fixing this issue by changing my namespace to the newer one in my WebApiConfig.cs
. Apparently it was one of the last files which I hadn't used the newer namespace name.
Well, once I changed that then my errors went away. Also, another fix for this same issue was to specify using old namespace name;
which also fixed it temporarily which got me to just rename it in the WebApiConfig.cs
with the new name.
Update-Package Microsoft.AspNet.WebApi.WebHost -reinstall
This worked for me. I was facing issues with the reference not being updated correctly on Update-package or even removing and installing the package again.
The above command reinstalls all dependencies, and usually does the trick whenever I face nuget package reference issue.
In my case I was getting a similar issue in Glabal.asax:
The name 'AreaRegistration' does not exist in the current context.
I already had System.Web.Mvc
namespace in Global.asax.cs
but the compiler was somewhat not aware of it, that is, the AreaRegistration
class was not being found.
What fixed the issue was executing the following command in Package Manager Console inside Visual Studio:
PM> Update-Package -reinstall
After NuGet reinstalled all the project's packages, the missing class names appeared and the code built successfully.
Something is broken in Visual Studio\NuGet restore pipeline...
in my asp.net webform based on 4.5, adding System.Web.Routing dll and below import in global.aspx resolved the problem
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.Http" %>
Also try doing the opposite (no offense) to what David Bohunek suggests. I tried Davids suggestion to no avail. Then I would up removing that reference that was referenced directly in the "Assemblies" section.
Then I removed the Web Api 2.2 and Web Api 2.2 Web Host Nugets, performed a clean and then JUST added back the Web Api 2.2 Web Host NuGet.
Try that. Good luck, it worked for me.