c# - RazorEngine 解析抛出无法编译

标签 c# .net razorengine

我正在尝试用这一行编译一个 razor 文件

RazorEngine.Razor.Parse("Hello world");

但它只是抛出

base {System.Exception} = {"Unable to compile template. Source file 'C:\\Windows\\TEMP\\vlu4zahf.0.cs' could not be found\n\nOther compilation errors may have occurred. Check the Errors property for more information."}

错误属性如下所示:

[0] = {error CS2001: Source file 'C:\Windows\TEMP\vlu4zahf.0.cs' could not be found}
[1] = {warning CS2008: No source files specified}

所以没有好的资料。

我正在运行 .NET 4.0 和 Razor Engine 3.2.0.0

更新1

我已在 RazorEngine 中找到此行的错误

Tuple.Create(
                compileResult.CompiledAssembly.GetType("CompiledRazorTemplates.Dynamic." + context.ClassName),
                compileResult.CompiledAssembly);

最佳答案

这很可能是编译 razor 文件的用户帐户的权限问题。 确保它对 C:\Windows\Temp 具有几乎完全的控制权限

请参阅此处了解背景信息: http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/85f9b330-a938-4afe-a615-db83085e52d2/

关于c# - RazorEngine 解析抛出无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15805434/

相关文章:

c# - Web API引发验证错误

c# - 实现规范设计模式以检查一系列字符串属性

c# - 如何在内存中创建 XML 文档并从中获取字符串

c# - 内联汇编代码以获取CPU ID

javascript - Chrome 的 Bootstrap 日期选择器问题

c# - 如何使用 C# 创建 appdata 文件夹

c# - 学习设计模式的资源

c# - 跨线程操作问题

asp.net-mvc - 在 MVC 中使用 Razor 时如何取消选中默认单选按钮?

c# - 将多个模板与单独的 View 模型与 RazorEngine 一起使用