【问题标题】:RazorEngine: Razor.Parse throws FileNotFoundException every once in a whileRazorEngine:Razor.Parse 每隔一段时间抛出 FileNotFoundException
【发布时间】:2017-06-13 12:41:55
【问题描述】:

我在使用 RazorEngine(版本 3.4.1.0)时遇到问题。

我在服务中使用Razor.Parse 方法和非常简单的模板,该服务每隔几分钟就会启动一次,并且它在大多数情况下都可以正常工作,但它时不时地向我抛出这个异常:

System.IO.FileNotFoundException: 找不到文件“C:\Users\username\AppData\Local\Temp\cw3sv4yk.dll”。 文件名:'C:\Users\username\AppData\Local\Temp\cw3sv4yk.dll'

cw3sv4yk是一个随机生成的名字)

以前有没有人遇到过这个问题,如果有的话 - 任何关于解决方案的提示?

谢谢, 普热梅克

编辑:

我刚刚注意到我偶尔也会遇到此异常:

RazorEngine.Templating.TemplateCompilationException:无法编译 模板。元数据文件 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' 无法打开 -- '进程无法访问文件,因为它 正在被另一个进程使用。'\n\n其他编译错误可能 已经发生。查看 Errors 属性以获取更多信息。

EDIT_2: 还有一个不时抛出的异常:

System.ArgumentException:需要类名

【问题讨论】:

    标签: c# razor razorengine


    【解决方案1】:

    使用缓存模板的Razor.Parse 方法的重载版本为我们解决了这个问题:

    /// <summary>
    /// Parses and returns the result of the specified string template.
    /// </summary>
    /// <typeparam name="T">The model type.</typeparam>
    /// <param name="razorTemplate">The string template.</param>
    /// <param name="model">The model instance.</param>
    /// <param name="cacheName">The name of the template type in the cache or NULL if no caching is desired.</param>
    /// <returns>The string result of the template.</returns>
    public static string Parse<T>(string razorTemplate, T model, string cacheName)
    

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 2023-04-03
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      相关资源
      最近更新 更多