Could not load file or assembly System.Web.Razor or one of its dependencies.

  • Updated

After copying an Episerver solution to a new environment the following error may occur in the Log4Net logs. 

2017-12-05 12:53:09,615 [1] ERROR EPiServer.Framework.Initialization.InitializationEngine: Type lookup failed detail #1 LoaderException (limit 20): System.IO.FileLoadException: Could not load file or assembly 'System.Web.Razor, Version=, 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)
File name: 'System.Web.Razor, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

  1. Open the Package Manager Console
  2. Tools > NuGet Package Manager > Package Manager Console
  3. Change the package source to Microsoft and .Net.
  4. Change the project to the one you are debugging.
  5. Run the following command.
    Update-Package Microsoft.AspNet.Mvc -Reinstall