2017-06-13 67 views
1

拋出FileNotFoundException異常每一次我在與RazorEngine(版本3.4.1.0)的問題。RazorEngine:Razor.Parse在一段時間

我使用Razor.Parse法在火災每隔幾分鐘服務非常簡單的模板,它的工作,而不大部分時間的任何問題,但每一個現在,然後灑在我這個例外:

System.IO.FileNotFoundException: 找不到文件'C:\ Users \ username \ AppData \ Local \ Temp \ cw3sv4yk.dll'。 文件名: 'C:\ Users \用戶名\ AppData \本地的\ Temp \ cw3sv4yk.dll'

cw3sv4yk是一個隨機生成的名稱)

有沒有人碰到了這個問題之前,如果所以 - 提示解決方案是什麼?

感謝, Przemek

編輯:

我剛剛注意到,我也越來越此異常偶見:

RazorEngine.Templating.TemplateCompilationException:無法編譯 模板。元數據文件 'c:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ mscorlib.dll' 無法打開 - '進程無法訪問該文件,因爲它正被另一個進程使用。'\ n \ n其他編譯錯誤可能發生在 。檢查錯誤屬性以獲取更多信息。

EDIT_2:

System.ArgumentException:類名是必需的

回答

0

使用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)