剛開始使用NVelocity(v1.1.1),它似乎工作得很好。NVelocity:「無法從封閉的TextReader讀取」
只有一件小事讓我惱火。我設置了VS2010,每次拋出一個異常即使它在某處被處理時也會被中斷,並且在運行下面的代碼時,它始終在調用Evaluate時中斷,表明它「無法從關閉的TextReader讀取」(ObjectDisposedException )。我沒有NVelocity的源代碼,所以我無法調試。
我是否錯過了導致此問題的設置?這只是NVelocity中的一個無害的錯誤嗎?結果很好,對我來說,這似乎是不太正確的。
var velocity = new VelocityEngine();
var properties = new ExtendedProperties();
var context = new VelocityContext(fieldValues);
properties.AddProperty("velocimacro.library", string.Empty); // no library
velocity.Init(properties);
using (var writer = new StringWriter())
{
velocity.Evaluate(context, writer, null, templateContents);
return writer.ToString();
}
異常堆棧跟蹤:
在System.IO .__ Error.ReaderClosed()在 System.IO.StringReader.Read(CHAR []緩衝液,的Int32索引,的Int32計數)
在NVelocity.Runtime.Parser.VelocityCharStream.FillBuff()在 C:\ ... \ SRC \ NVelocity \運行\分析器\ VelocityCharStream.cs:行313
對於你的問題沒有太大的回答,但如果你願意潛入其中,似乎[源代碼可用](http://nvelocity.codeplex.com/)。 – Jeroen 2012-03-15 13:02:36
謝謝,我一直在尋找自己的源代碼,但是你鏈接到的項目是原始NVelocity項目的一個分支。我*可以*檢查分叉版本,看看我能否找到問題的根源。你知道1.1.1版的原始源代碼是否可用? – bernhof 2012-03-15 13:24:57
@Jeroen:這不是canon NVelocity資料庫。授權存儲庫位於https://github.com/castleproject/MonoRail/tree/master/MR2/NVelocity。 codeplex中的一個是沒有維護的分支。 – 2012-03-15 13:36:06