C# RazorEngine:Razor.Parse每隔一段时间就会抛出FileNotFoundException

C# RazorEngine:Razor.Parse每隔一段时间就会抛出FileNotFoundException,c#,razor,razorengine,C#,Razor,Razorengine,我对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.

我对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属性

编辑2: 还有一个不时抛出的异常:

System.ArgumentException:需要类名


使用重载版本的
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)
//
///解析并返回指定字符串模板的结果。
/// 
///模型类型。
///字符串模板。
///模型实例。
///缓存中模板类型的名称,如果不需要缓存,则为NULL。
///模板的字符串结果。
公共静态字符串解析(字符串razorTemplate、T模型、字符串cacheName)