Can't load System.Web.Mvc even though it's clearly there and is correct version

463 Views Asked by At

I'm getting one of these:

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

It continues:

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///D:/Websites/Reporting/2016-02-18.2/
LOG: Initial PrivatePath = D:\Websites\Reporting\2016-02-18.2\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Websites\Reporting\2016-02-18.2\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/reports/7733280c/d5adf208/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/reports/7733280c/d5adf208/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///D:/Websites/Reporting/2016-02-18.2/bin/System.Web.Mvc.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

The correct version of System.Web.Mvc is located in D:\Websites\Reporting\2016-02-18.2\bin. I've been fighting with this project all night, but I can't seem to get past this issue. For what it's worth, I do also have the binding redirect in the web.config.

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

I'm usually pretty good at dll hell type stuff, but this one has me puzzled because as far as I can tell it looks like it's telling me it can't find the file that's sitting in the bin directory and is the version it's looking for.

Where do I go from here?

EDIT: I should point out that it works fine in development and it also works fine when I deploy the project somewhere on the the development machine. But when I deploy to our staging server I am getting this. Not sure what could be different. I did have an issue at first where the TFS builds were grabbing the wrong dlls (even though I had copy local = true and the hint path was there it still grabbed incorrect versions and I had to delete the old nuget package folders to prevent this). I've been getting this error a lot, but this is the first time I got it and the file was actually the correct version when I checked it (and double, triple, and quadruple checked it).

2

There are 2 best solutions below

0
BVernon On

I was using 5.0.0.0 in various places in the web.config in the Views folder. I don't understand why the binding redirect wouldn't take care of this issue but when I updated them to 5.2.3.0 it finally started working.

1
Rajshekar Reddy On

The dll version in your path C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\ must have the proper version. This is the where the application reads it (from the system). You got to update this, Else install the required version using Nuget which will update this location dll too. and for your comment I should point out that it works fine in development and it also works fine when I deploy the project somewhere on the the development machine. the reason is the dll version in the above mentioned path was what the application required, hence you didn't get any error.