Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window Update Broke MVC Application

I ran Windows Update yesterday and its introduced some problems when I'm trying to release a new version of my ASP.NET MVC 4 project.

The application compiles and runs okay locally, however when I push the version up to a test-site on my webserver it fell over with the error message:

System.Web.HttpCompileException: (0): error CS1705: Assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

After some research I found that this is due to an update from 4.0.0.0 to 4.0.0.1. I removed the System.Web.Mvc dll from my project and readded the dll that has the later version. Again everything works locally but not on the web. I then went through the web.config's and changed any mention of 4.0.0.0 to 4.0.0.1. Likewise this continues to work internally but fails externally. The error message is:

    
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) 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: 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)

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

I believe this has something to do with Elmah that I'm using for the error handling.

I tried to reinstall from Nuget as suggested here: Windows update caused MVC3 and MVC4 stop working but that hasn't worked and I'm getting the same error.

Added info: The server hasn't yet been updated, I'm concerned that updating this might break the existing live version.

like image 802
Jay Avatar asked Oct 17 '14 12:10

Jay


People also ask

Is .NET MVC outdated?

Is the framework outdated? ASP.NET MVC is no longer in active development. The last version update was in November 2018. Despite this, a lot of projects are using ASP.NET MVC for web solution development.

Is MVC 4 still supported?

We have many applications developed with ASP.NET MVC 4 and below versions. As per the Microsoft Support Policy, the retirement date for ASP.NET MVC is July 1st, 2019.


1 Answers

The error message is telling me that you have specified an incorrect version number for the MVC assembly in one of your config files. Find it the config file with the incorrect version and change it to match whatever version you are using (you mentioned 4.0.0.1 above). You need to check all the config files including

  • The one in the project root
  • The one in the Views folder

You could also do an assembly redirect in your config file to take care of this as well -- If its failing due to a third party lib this might be the most appropriate action to take.

Based on your feedback id suggest using a binding redirect. Add this to your main web.config..

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
like image 130
iamkrillin Avatar answered Oct 26 '22 11:10

iamkrillin