Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0' or one of its dependencies

I am adding Ninject in MVC project using the following commands in Package Manager Console:

Install-Package Ninject -version 3.0.1.10
Install-Package Ninject.Web.Common -version 3.0.0.7
Install-Package Ninject.MVC3 -Version 3.0.0.6

When I run the application, I get error like this:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

like image 699
Dani Petrick Avatar asked Jun 04 '14 03:06

Dani Petrick


4 Answers

Update the Application web.config File

Be sure to make these changes in the app web.config file, not the web.config file in the Views folder.

 <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
             <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
             <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
         </dependentAssembly>
      </assemblyBinding>
 </runtime>
like image 82
amighty Avatar answered Nov 11 '22 13:11

amighty


If you're following the Pro ASP.NET MVC 5, follow these steps to resolve the issue:

  1. In your project tree in VS, right-click References and go to Manage NuGet Packages.
  2. Go to Online, nuget.org and search for ninject.
  3. Install Ninject, Ninject.Web.Common and Ninject.MVC5 (the book says to install MVC3).
  4. In the Manage NuGet Packages menu (from step 1), go to Updates, nuget.org.
  5. Update all modules, especially Microsoft ASP.NET MVC.
like image 28
mihai Avatar answered Nov 11 '22 12:11

mihai


I have a Microsoft ASP.NET Web API 2.2 project which use Ninject.

To fix the problem, I have to install NuGet Package Microsoft ASP.NET MVC 4 for my project because Ninject requires System.Web.Mvc. By doing so, Visual Studio will add System.Web.Mvc to project's reference.

Also, you should set Copy Local = True for the property of System.Web.Mvc reference, so the DLL will be copied to Bin folder. The DLL does not come with standard .NET Framework. It is part of the ASP.NET MVC Package.

like image 3
Tony Avatar answered Nov 11 '22 13:11

Tony


I expanded references and when I hovered over System.Web.Mvc, I observed that its version is 4.0.0.1. And its path is strangely C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies. My packages.config showed the the corresponding nuget package is Microsoft.AspNet.Mvc.5.2.3. The reference seems to be wrong. So removed the reference from the project. Then uninstalled the nuget package using the following command.

uninstall-package Microsoft.AspNet.Mvc -force

Note force in the command.

Then I reinstalled it by the following command

install-package Microsoft.AspNet.Mvc -version 5.2.3.0

Now I ensured that the referenced dll is correctly pointing to nuget one

D:\Vivek\Code1\Sept17\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll

Now when I ran I discovered similar problem with System.Web.Webpages.Razor(Microsoft.AspNet.WebPages nuget) and System.Web.Razor(Microsoft.AspNet.Razor nuget). So I removed those as well and reinstalled the corresponding nuget packages.

Then it finally worked.

like image 2
VivekDev Avatar answered Nov 11 '22 12:11

VivekDev