Could not load file or assembly 'System.Web.Razor' or one of its dependencies
Asked Answered
B

6

28

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>

Biomass answered 8/4, 2013 at 8:18 Comment(3)
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/installedWaits
I download System.web.razor.dll version 2 from 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)"Biomass
can't help you there sorry..Waits
B
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.

Boong answered 8/4, 2013 at 20:6 Comment(5)
but I'm not using MVC. I'm using Nancy. And installed via Nuget the following packages: <package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net45" /> <package id="Nancy" version="1.4.3" targetFramework="net45" /> <package id="Nancy.Viewengines.Razor" version="1.4.3" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" />Trophy
... 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.Trophy
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?Trophy
Not Worked for me :(Scarron
Copying dlls should always be a last resort. Check out the answer of @Yasel instead.Revenge
Y
16

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
Ytterbium answered 3/1, 2018 at 14:36 Comment(2)
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.Arceliaarceneaux
@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, failsYtterbium
P
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)

Pm answered 9/6, 2016 at 6:33 Comment(0)
S
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

Synchroscope answered 13/2, 2015 at 11:7 Comment(3)
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.Trophy
did step 2, 3, and even deleted obj folder, then 4 and 5 - does not work.Trophy
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.Actinia
G
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

Gabriel answered 3/8, 2017 at 12:10 Comment(1)
This fixed my issue as well. Was receiving multiple errors with "system.web.<thing> 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: microsoft.com/en-us/download/confirmation.aspx?id=30683Carnation
T
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

Telemachus answered 3/4, 2020 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.