Could not load file or assembly 'System.Web.Mvc' . How to use the correct reference?

Forums .NETCould not load file or assembly 'System.Web.Mvc' . How to use the correct reference?
Staff asked 1 year ago

Answers (1)

Add Answer
krishna kukadiya Marked As Accepted
Staff answered 1 year ago

The error “Could not load file or assembly ‘System.Web.Mvc'” typically occurs when the required assembly reference for MVC is missing or incorrect in your project. To use the correct reference for ‘System.Web.Mvc’, follow these steps:

  1. Verify .NET Framework version: Ensure that your project is targeting the correct version of the .NET Framework that is compatible with ASP.NET MVC.
  2. Add or update the reference: Right-click on your project in the Solution Explorer and select “Manage NuGet Packages.” In the NuGet Package Manager, search for “Microsoft.AspNet.Mvc” or “System.Web.Mvc” package and install it. This will add the correct reference to your project. Make sure to choose the version appropriate for your project’s .NET Framework version.
  3. Check project references: Verify that the correct reference to ‘System.Web.Mvc’ is added to your project references. Right-click on your project in the Solution Explorer and select “References.” In the References dialog, ensure that ‘System.Web.Mvc’ is listed. If it is missing, you can add it by clicking “Add Reference” and searching for ‘System.Web.Mvc’ in the Assemblies tab.
  4. Update web.config: Open your project’s web.config file and ensure that the correct assembly reference is added in the <compilation> section. The entry should look like this:
<compilation debug="true" targetFramework="4.6.1">
  <assemblies>
    <!-- Other assemblies... -->
    <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

Ensure that the version number in the assembly attribute matches the version you installed or the version appropriate for your project.

  1. Clean and rebuild the project: After making these changes, clean your solution (Build > Clean Solution) and then rebuild it (Build > Rebuild Solution) to ensure that all references are resolved correctly.

By following these steps, you should be able to resolve the “Could not load file or assembly ‘System.Web.Mvc'” error and use the correct reference for ASP.NET MVC in your project.

Subscribe

Select Categories