asp.net-mvc 无法加载文件或程序集 System.Web.WebPages.Razor, , Version=3.0.0.0 或其依赖项之一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21108375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly System.Web.WebPages.Razor, , Version=3.0.0.0 or one of its dependencies
提问by user2934829
I am using MVC 5, WCF and Unity framework in my application.
我在我的应用程序中使用 MVC 5、WCF 和 Unity 框架。
I am getting below error when I run WCF service:
运行 WCF 服务时出现以下错误:
Server Error in '/' Application.
Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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:
[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Mvc.PreApplicationStartCode.Start() +0
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +556
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9882460
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440
I have added System.Web.WebPages.Razor, Version=3.0.0.0 in WCF project, still same error persist.
我在 WCF 项目中添加了 System.Web.WebPages.Razor, Version=3.0.0.0,仍然存在相同的错误。
Do someone know how to resolve this error?
有人知道如何解决这个错误吗?
回答by Cybermaxs
Be sure that your project targets .net 4.5, that all references are valid and that web AspNet.WebPages.* are in the bin (Release/Debug) folder.
确保您的项目面向 .net 4.5,所有引用都有效,并且 web AspNet.WebPages.* 位于 bin (Release/Debug) 文件夹中。


You may also try to reinstall Microsoft.AspNet.WebPages nuget packages using this command in the package manager console
您也可以尝试在包管理器控制台中使用此命令重新安装 Microsoft.AspNet.WebPages nuget 包
> Update-Package –reinstall Microsoft.AspNet.WebPages
回答by Mike
I was encountering the exact error here (among a couple other missing reference errors) on my Win10 x64 system. My issue was (I believe), was caused by uninstalling something from add/remove that ripped out other dlls.
在我的 Win10 x64 系统上,我在这里遇到了确切的错误(以及其他几个缺失的参考错误)。我的问题是(我相信)是由于从删除其他 dll 的添加/删除中卸载某些内容引起的。
After scouring the internet for a solution, what finally worked for me was the answer here: https://stackoverflow.com/a/27785999/692124
在网上搜索解决方案后,最终对我有用的是这里的答案:https: //stackoverflow.com/a/27785999/692124
Download and install Web Pages Version 2
下载并安装网页版本 2
回答by Hemanth Suresh
I had same issue where WCF was showing error of unrelated MVC assembly (I have multiple MVC projects in solution which are using System.Web.WebPages.Razor, Version=3.0.0.0). I installed Microsoft.AspNet.WebPages package in the WCF project , ran WCF proj and It worked. After that I had uninstalled all Microsoft.AspNet.WebPages related packages. It worked fine.
我有同样的问题,WCF 显示不相关的 MVC 程序集错误(我在解决方案中有多个 MVC 项目,它们使用 System.Web.WebPages.Razor,版本 = 3.0.0.0)。我在 WCF 项目中安装了 Microsoft.AspNet.WebPages 包,运行 WCF proj 并且它工作正常。之后我卸载了所有与 Microsoft.AspNet.WebPages 相关的软件包。它工作得很好。

