无法加载文件或程序集“System.Web.Razor”或它的一个依赖(Could not load

2019-08-20 05:58发布

我用一把umbraco 4.11.6在我的网站(Web应用程序)。我的网站是在本地主机的工作(从Visual Studio 2012和IIS(V7)进行测试),但是当我从互联网空间中运行它,我得到了一个错误。 错误是:

无法加载文件或程序集“System.Web.Razor”或它的一个依赖。 在位于集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)

程序集加载跟踪:下列信息有助于确定程序集“System.Web.Razor”无法加载。

警告:程序集绑定日志记录被关闭。 要启用程序集绑定失败日志记录,注册表值!HKLM \ SOFTWARE \微软\融合EnableLog](DWORD)设置为1.注意:有一些与程序集绑定失败日志记录关联的性能损失。 要关闭此功能,请移除注册表值[HKLM \软件\微软\融合!EnableLog。

堆栈跟踪:

[FileLoadException:未能加载文件或程序集“System.Web.Razor”或它的一个依赖。 在位于集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)]

[FileLoadException:未能加载文件或程序集“System.Web.Razor,版本= 2.0.0.0,文化=中性公钥= 31bf3856ad364e35”或它的一个依赖。 在位于集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(的AssemblyName文件名,字符串的代码库,证据assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)+0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)210
System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔forIntrospection)242
System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark,布尔forIntrospection)17 System.Reflection.Assembly.Load(字符串assemblyString)35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串的AssemblyName,布尔starDirective)+122

[ConfigurationErrorsException:未能加载文件或程序集“System.Web.Razor,版本= 2.0.0.0,文化=中性公钥= 31bf3856ad364e35”或它的一个依赖。 在位于集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串的AssemblyName,布尔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(字符串preStartInitListPath)+203
System.Web.Compilation.BuildManager.ExecutePreAppStart()+152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager AppManager的,IApplicationHost APPHOST,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,异常appDomainCreationException)1151

[HttpException(0X80004005):无法加载文件或程序集System.Web.Razor,版本= 2.0.0.0,文化=中性公钥= 31bf3856ad364e35'或它的一个依赖。 在位于集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext的上下文)12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext的上下文)159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext的上下文)12722601

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.17929

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>

Answer 1:

相当多的方法来解决这个问题:

  1. 在Web服务器上安装MVC(这并不总是可能的)。

  2. 在Visual Studio中,您可以设置的dll复制到本地的身材,请参阅下面的文章(请注意MVC的DLL略有改变名称,但它给你的过程) http://haacked.com/archive/2008/11/03/仓部署,aspnetmvc.aspx

  3. 从您的GAC相应的DLL复制到一把umbraco网站的bin文件夹。 要做到在资源管理器中打开这个“%WINDIR%\ Microsoft.NET \装配\ GAC_MSIL”,你会发现所有安装在GAC中的DLL,您可以适当的版本复制到您的项目。 这类似于上面的方法,而是绕过建设项目。

在文件方面,你可能会需要的不仅仅是System.Web.Razor.dll然而,这将为所有丢失的文件的工作更多。



Answer 2:

重新安装包Microsoft.AspNet.Razor ,如肾上腺素DJ 发布 。 要做到这一点,最好的方法是使用Update-Package命令,因为Install-Package命令不提供一个选项,以强制进行重新安装,请参阅文档 。

PM> Update-Package Microsoft.AspNet.Razor -reinstall


Answer 3:

这些解决方案的非帮我:要么是因为要么是因为我不想直接包括DLL文件,而无需使用的NuGet我不能在服务器上安装任何东西。

我使用的解决方案是安装/重新命名为NuGet包Microsoft.AspNet.Razor(微软ASP.Net剃刀2.0.20710)



Answer 4:

  1. 删除的NuGet明确的“临时”文件夹。
  2. 从项目源删除NuGet包,然后用包管理器重新安装NuGet包。
  3. 删除bin文件夹。
  4. 清洁工程和构建项目。
  5. 运行项目。

完成



Answer 5:

我不想安装Visual Studio开发环境,所以我在Windows Server 2016机器上安装AspNetMVC4Setup.exe,它解决了这个问题。 安装程序从微软网站下载。



文章来源: Could not load file or assembly 'System.Web.Razor' or one of its dependencies