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

7

24

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)

Pardoner answered 4/6, 2014 at 3:37 Comment(8)
And what version of System.Web.Mvc you have?Locomotion
Why are you installing such old versions? Just install Ninject.MVC3 .. latest version.. and it will pull in the dependencies you require.Benildas
Alexei, I am not sure how to check its version. I thinks I am using Version=3.0.0.0Pardoner
Simon, Since I am new to MVC, I try to follow some tutorial that use old version. But I try using latest version, and the output is still samePardoner
Open "bin" folder in explorer and right click on System.Web.Mvc there - details tab will have the version. Likely you need "assembly redirect" to map older version to new one (or other way around).Locomotion
Easiest thing to do is go into the Nuget GUI (right click references -> Manage Nuget References).. uninstall everything. Then go into your bin folder and delete everything. Then just install them fresh with no specific version.Benildas
Alexei: the version is 5.0.11001.0. I try to redirect the assembly in web.config, but the error still same :(Pardoner
Simon, I already try the same exactly you said. But the output is still same with previousPardoner
D
17

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>
Dermatoid answered 17/7, 2014 at 17:57 Comment(2)
I had this issue somehow. I must have updated the MVC NuGet package and ended up with the mismatched versions.Lewanna
Wasn't marked as the answer so I don't know if this answered Dani's question - but answered mine :) ThanksBoardman
S
8

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.
Supranatural answered 11/10, 2014 at 9:13 Comment(0)
E
3

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.

Enclitic answered 25/11, 2014 at 22:58 Comment(0)
A
2

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.

Anew answered 12/12, 2017 at 12:4 Comment(0)
A
1

if amighty's Answer did not worked with you, try this

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

this solution came after struggling with this error for long hours

Aeriell answered 19/9, 2016 at 22:50 Comment(1)
I had the error and had to change the newVersion to 5.0.0.0 to get it working. Then after a few months it suddenly stopped working in the middle of development, after the 100th rebuild. This time I had to change it back to 5.2.3.0.Cnidus
P
0

I was facing this issue with my application.

In my solution, we had a web application project and a web-api project. The web application was consuming the web-api.

The fix for my issue was that the Mvc dll version in the Web application was different from that of the web-api project. So, whenever I was trying to hit the web-api, it was throwing up error. I just ensured that both the projects have the same Mvc dll version and things started working fine. You can use NuGet Package Manager for this.

Just mentioning it for the reference of others who might be facing a similar scenario.

Pyrosis answered 2/3, 2016 at 7:16 Comment(0)
B
0

In my case, the missing assembly was already included as a reference to the project. I solved by selecting it then setting its "Copy Local" property to True. I "published" my project to IIS using web-deploy from Visual Studio. This time the assembly was copied to the \bin folder of the website.

Bloc answered 20/9, 2018 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.