27

I used Umbraco 4.11.6 in my website(web application).My website is worked in localhost(tested from Visual studio 2012 and IIS(v7)) but when I run it from internet space I got an error. The error was:

Could not load file or assembly 'System.Web.Razor' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Razor' 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].

Stack Trace:

[FileLoadException: Could not load file or assembly 'System.Web.Razor' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'System.Web.Razor, Version=2.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)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17 System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122

[ConfigurationErrorsException: Could not load file or assembly 'System.Web.Razor, Version=2.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)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12761078
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Razor, Version=2.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)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

a part of WebConfig:

<runtime>
<!-- Old asp.net ajax assembly bindings -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

x19
  • 8,277
  • 15
  • 68
  • 126
  • check the assembly redirect in your web.config. you might find some redirect there, that references to a version of System.web.razor that you may have not referenced/installed – Vogel612 Apr 08 '13 at 08:20
  • I download System.web.razor.dll version 2 from http://originaldll.com/file/system.web.razor.dll/31004.html and replace it. but I got an error. "Could not load file or assembly 'System.Web.Razor' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)" – x19 Apr 08 '13 at 08:50
  • can't help you there sorry.. – Vogel612 Apr 08 '13 at 10:20

6 Answers6

18

Quite a few ways to fix this:

  1. Install MVC on the web server (which is not always possible).

  2. In visual studio you can set dlls to copy to local on build, see the following article (please note MVC dlls have changed names slightly but it gives you the process) http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx

  3. Copy the appropriate dlls from your GAC into the bin folder of the umbraco site. To do this open "%windir%\Microsoft.NET\assembly\GAC_MSIL" in explorer and you will find all of the dlls installed in the GAC and you can copy the appropriate versions into your project. This is similar to the above method but bypasses building the project.

In terms of files you will likely need more than just System.Web.Razor.dll however this will work for all of the missing files.

gavstorey
  • 204
  • 2
  • 2
  • but I'm not using MVC. I'm using Nancy. And installed via Nuget the following packages: – pashute Dec 28 '15 at 08:55
  • 1
    ... and System.Web.Razor is shown in my references as copy local. It's v4.0.30319. I removed the reference, and builds ok, but then no app running (forbidden). Reinstalled NUGET and brings back same referenced version. Help!! I have no idea what to do. – pashute Dec 28 '15 at 09:13
  • In answer 3 you say: "and copy the apporpriate versions into your project." But that's the question!!! HOW DO WE KNOW what's the appropriate version? – pashute Dec 28 '15 at 09:15
  • Not Worked for me :( – QMaster Mar 02 '17 at 13:22
  • 1
    Copying dlls should always be a last resort. Check out the answer of @Yasel instead. – Didii Jul 02 '19 at 14:26
14

Reinstall package Microsoft.AspNet.Razor, like ADreNaLiNe-DJ posted. The best way to do this is using Update-Package command, because The Install-Package command does not provide an option to force a reinstall, see docs.

PM> Update-Package Microsoft.AspNet.Razor -reinstall
Yasel
  • 2,920
  • 4
  • 40
  • 48
  • I've found that using `Update-Package` can take forever on a large solution, as it basically reinstalls every package on every project. Consequently, I usually try `Uninstall-Package Package-Name -Force`, followed by `Install-Package Package-Name`. That usually seems to work for me, and it takes about 30 seconds instead of 30 minutes. – Ken Smith Jan 19 '18 at 14:42
  • @KenSmith in this case `Update-Package Microsoft.AspNet.Razor -reinstall`, will only reinstall this especific package and its dependencies (none) in the specific project, so this should not be a case of excessive execution time. I'm not really a fan of forcing things, in my case trying to uninstall the package, without the option -Force, fails – Yasel Jan 19 '18 at 15:35
6

Non of these solutions helped me : either because i can't install anything on the server either because i prefer not including dlls directly without using Nuget.

The solution i used is to install/reinstall the nuget package named Microsoft.AspNet.Razor (Microsoft ASP.Net Razor 2.0.20710)

ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35
4
  1. Delete Nuget clear "Temp" folders.
  2. Delete Nuget package from project source and then re-install Nuget Package using package manager.
  3. Remove bin folder.
  4. Clean project & build project.
  5. Run project.

Done

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67
  • 1
    What does #1 mean? Do you mean: In Nuget - remove all packages? - obviously not - that is step 2. Also: which "temp" folders do I have to clear and how? Do you mean delete the obj and Debug/Release folders in my build? - obviously not - that is step 3. – pashute Dec 28 '15 at 08:38
  • did step 2, 3, and even deleted obj folder, then 4 and 5 - does not work. – pashute Dec 28 '15 at 08:57
  • as for step 1 - I deleted the '%TEMP%\nuget' foldercontents, deleted the packages folder in the solution root(step 2), did all other stages and it worked. – Yaron Mar 22 '20 at 22:17
3

I did not want to install visual studio and development environment, so I have installed AspNetMVC4Setup.exe in Windows server 2016 machine and it solved the problem. The installer was downloaded from Microsoft website.

Properties of AspNetMVC4Setup.exe file

Shantu
  • 145
  • 11
  • This fixed my issue as well. Was receiving multiple errors with "system.web. not found" and this fixed it for my project. EVEN IF I had installed Visual Studio 2017 with MVC4 selected. Apparently it doesn't install some windows references. This is where I've downloaded AspNetMVC4Setup from: https://www.microsoft.com/en-us/download/confirmation.aspx?id=30683 – OrionMD Sep 03 '19 at 12:59
0

The answer, at this link, worked for me:

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

Bob Horn
  • 33,387
  • 34
  • 113
  • 219