我有一个正在运行的 ASP.NET 5 RC1 应用程序。现在我已经在 Shawn Wildermuth 的博客的帮助下将应用程序转换为当前的 ASP.NET Core 1.0.0 版本。 api Controller 确实可以毫无问题地运行。但是,一旦我尝试打开 *.cshtml 文件,我就会收到以下错误:
Microsoft.AspNetCore.Server.Kestrel: Error: Connection id "0HKTRFIA80GPS": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
rkq2e32e.x02(16,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
...
rkq2e32e.x02(37,10): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
rkq2e32e.x02(37,10): error CS0518: Predefined type 'System.Object' is not defined or imported
有人知道我可以从哪里开始吗?
最佳答案
我通过将 project.json 与来自正在运行的 ASP.NET Core 版本的新 project.json 进行比较,找到了异常的原因。其实我没有找到原因 - 我只是发现添加 preserveCompilationContext 后异常消失了 - 真正进入我的 project.json:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
}
关于asp.net - 将 ASP.NET 从 RC1 升级到核心后出现 Razor 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38739597/