Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception – Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.1…'

Tags:

asp.net-mvc

There is a problem – only when I request one single controller – I get the exception:

Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.1, 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

It's strange because in my config file I see that the version is 4.0.0.0 and and all the other controllers are fine and only when I upload the application on the server this thing happens.

like image 706
Tania Marinova Avatar asked Jun 30 '15 09:06

Tania Marinova


2 Answers

This is a known issue. Seems you have migrated recently from 3.0 to 4.0 or this application is a fresh clone from the repository. The one single controller may not have nuget restored. I have also faced this issue. I got this msdn link and browsing it had a solution. Here are the steps mentioned.

The problem can be resolved by implementing one of the following solutions:

  1. (Preferred) Install Microsoft.AspNet.Mvc from the NuGet gallery (this will install a binding redirect in your web.config). You can do this from the NuGet package manager or the NuGet console inside Visual Studio:

    Install-Package Microsoft.AspNet.Mvc -Version -Project PROJECTNAME

    MVC 4 version: 4.0.40804.0

    MVC 3 version: 3.0.50813.1

  2. Manually update the reference to System.Web.MVC.dll (don’t use the one in the GAC).

    Try the Add Reference -> Assemblies -> Extensions dialog box.

In either case ensure that the Copy Local project property for the assembly is set to true so it ends up in your bin folder which is needed for deployment. There is a known NuGet bug that resets the Copy Local flag: https://nuget.codeplex.com/workitem/4344

Install Nuget Package Microsoft.AspNet.Mvc for all the project referencing System.Web.Mvc dll Hope this solves your problem

like image 116
staticvoidmain Avatar answered Nov 15 '22 01:11

staticvoidmain


I got this build error on a VSO agent thanks to the ASP.Net assembly resolve weirdness. I had changed some of my build configurations and Visual Studio modified the output directory for the MVC project to \bin\x86\Debug or something similar.

This had bitten me before and I remembered ASP.Net wants to be built to \bin ONLY.

So when you get any kind of "reference could not be found" on build time, remember to check that your build output directory is only \bin:

enter image description here

More on the problem here: Changing output directory for asp.net project in Visual Studio

Hope this helps someone.

like image 32
Andre Luus Avatar answered Nov 15 '22 01:11

Andre Luus