无法加载文件或程序集“System.Web.Razor”或其依赖项之一
我在我的网站(网络应用程序)中使用了Umbraco 4.11.6。我的网站在localhost中工作(从Visual Studio 2012和IIS(v7)测试)但是当我从互联网空间运行它时出现错误。 错误是:
无法加载文件或程序集“System.Web.Razor”或其依赖项之一。 定位的程序集的清单定义与程序集引用不匹配。 (HRESULTexception:0x80131040)
程序集加载跟踪:以下信息有助于确定无法加载程序集“System.Web.Razor”的原因。
警告:assembly绑定日志记录已关闭。 要启用程序集绑定失败日志记录,请将注册表值[HKLM \ Software \ Microsoft \ Fusion!EnableLog](DWORD)设置为1.注意:程序集绑定失败日志记录会导致一些性能损失。 要关闭此function,请删除注册表值[HKLM \ Software \ Microsoft \ Fusion!EnableLog]。
堆栈跟踪:
[FileLoadException:无法加载文件或程序集’System.Web.Razor’或其依赖项之一。 定位的程序集的清单定义与程序集引用不匹配。 (HRESULTexception:0x80131040)]
[FileLoadException:无法加载文件或程序集’System.Web.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35’或其依赖项之一。 定位的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的exception: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:无法加载文件或程序集’System.Web.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35’或其依赖项之一。 定位的程序集的清单定义与程序集引用不匹配。 (HRESULTexception: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):无法加载文件或程序集’System.Web.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35’或其依赖项之一。 定位的程序集的清单定义与程序集引用不匹配。 (HRESULTexception:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+12722601版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.17929
WebConfig的一部分:
有很多方法可以解决这个问题:
-
在Web服务器上安装MVC(这并不总是可行)。
-
在visual studio中,您可以将dll设置为在构建时复制到本地,请参阅以下文章(请注意MVC dll稍微更改了名称,但它为您提供了流程) http://haacked.com/archive/2008/11/03/仓部署,aspnetmvc.aspx
-
将适当的dll从GAC复制到umbraco站点的bin文件夹中。 为此,在资源管理器中打开“%windir%\ Microsoft.NET \ assembly \ GAC_MSIL”,您将找到GAC中安装的所有dll,您可以将相应的版本复制到项目中。 这与上述方法类似,但绕过构建项目。
在文件方面,您可能需要的不仅仅是System.Web.Razor.dll,但这适用于所有丢失的文件。
重新安装包Microsoft.AspNet.Razor ,就像ADreNaLiNe-DJ一样。 执行此操作的最佳方法是使用Update-Package
命令,因为Install-Package
命令不提供强制重新安装的选项,请参阅docs 。
PM> Update-Package Microsoft.AspNet.Razor -reinstall
这些解决方案中没有一个帮助我:因为我无法在服务器上安装任何东西,因为我不想在不使用Nuget的情况下直接包含dll。
我使用的解决方案是安装/重新安装名为Microsoft.AspNet.Razor的nuget包(Microsoft ASP.Net Razor 2.0.20710)
- 删除Nuget清除“Temp”文件夹。
- 从项目源删除Nuget包,然后使用包管理器重新安装Nuget包。
- 删除bin文件夹。
- 清洁项目和构建项目。
- 运行项目。
完成
我不想安装visual studio和开发环境,所以我在Windows server 2016机器上安装了AspNetMVC4Setup.exe,它解决了这个问题。 安装程序是从Microsoft网站下载的。