Assembly Not Found in HttpConfiguration

Compilation Error Caused by Json Hidden Dependency on HttpConfiguration
Possible Solutions:
1. To add a reference, right-click the project node in Solution Explorer and select “Add Reference”. Then, in the Add Reference dialog box, go to the Assemblies tab. However, an error is displayed in the startup.cs file. How can this be resolved?
code:-
2. After installing the Microsoft ASP.NET Web API 2.2 Core Libraries NuGet package, the issue can be resolved.
3. The startup.cs file contains references to the following Owin packages:
This is how the startup.cs file looks like:
4. HttpConfiguration is a configuration of HttpServer instances.

Question:

As I work on my MVC4 website, I am encountering a
strange error
issue that is preventing me from progressing. Below is the code I am currently using.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace MyProject
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

The assembly ‘HttpConfiguration’ is not found in the ‘
system.web.http
‘ namespace. The error message suggests that there might be a missing using directive or an assembly reference causing this issue.

The RouteParameter field marked as readonly is not being recognized by it. I suspect that the issue might be related to the version, as my
system.web dll
is running on version 4.0.0.0.

It’s worth noting that Intellisense recognizes the .Http dll when I type “using System.Web. “.

Despite its parameters being present in the code, they are not recognized.


Solution 1:

After creating the site, I updated all packages using Nuget. However, since I wasn’t going to use Entity Framework, I uninstalled it. To uninstall that package, I also had to uninstall Microsoft.AspNet.Providers.Core 1.2, which I did. This solved the issue.

The project got disrupted due to a missing package. To rectify it, I chose to restart the project from scratch instead of using the Update-Package command in the PM Console, which could have restored all lost packages. Although this may have seemed like a drastic solution, it was necessary as I had made more errors than progress.

Thanks anyway!


Solution 2:


While attempting to clone an MVC 4.0 application that had previously functioned without issue, I encountered an error. It became apparent that the

Microsoft.Net.Http

NuGet package was not restoring correctly. To resolve the issue, I utilized the NuGet console.


Update-Package -reinstall Microsoft.Net.Http


Solution 3:


To tackle this problem, I had a distinct approach than others. Although the issue was identical to the one mentioned above, I was working on a project which needed to be downgraded from .net 4.5 to .net 4.0.

The assembly ‘HttpConfiguration’ cannot be found in the namespace ‘
System.Web.Http
‘. It is possible that a using directive or assembly reference is missing.

While browsing a blog post, I discovered a connection between

Newtonsoft.Json

and

HttpConfiguration

. In order to remedy the situation, I eliminated any mention of

Newtonsoft.Json

in the project and the

packages.config

document. Eventually, I reinstalled

Newtonsoft.Json

using the
package manager
console.

Install-Package Newtonsoft.Json

Due to other dependencies, I couldn’t uninstall

Newtonsoft.Json

from the package management console, which led to the need for manual removal of the reference.

The article on Newtonsoft.Json’s hidden dependency causing compilation issues can be accessed through this link.


Solution 4:

To add a reference, simply right-click on the project node in the Solution Explorer and select the “Add Reference” option.

To add a reference, go to the Add Reference dialog box and choose the Assemblies tab. Then, simply type “system.web.http” in the search bar located at the top right corner.

Choose the desired components for referencing. If they are already selected, remove the reference before adding it again.

Kindly inform me if the rebuilt project is functional. Thank you.

Frequently Asked Questions