我在最近的SVN提交中使用了DotLiquid,并尝试了下面的“简单”代码。
Template.NamingConvention = new CSharpNamingConvention();
Book selectedBook = (Book)this.booksList.SelectedObject;
string pathToTemplate = "..\\..\\..\\Resources\\templates\\white.html";
string res = "";
res = File.ReadAllText(pathToTemplate);
// Parse and compile the template
Template template = Template.Parse(res);
Console.WriteLine(template.RenderAndRethrowErrors(Hash.FromAnonymousObject(new { book = selectedBook })));错误发生在RenderAndRethrowErrors方法中。
下面是堆栈跟踪:
在DotLiquid.Context.HandleError(Exception ex)
at DotLiquid.Block.<>c__DisplayClass1.<RenderAll>b__0(Object token)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at DotLiquid.Block.RenderAll(List`1 list, Context context, StringBuilder result)
at DotLiquid.Block.Render(Context context, StringBuilder result)
at DotLiquid.Template.RenderInternal(Context context, Hash registers, IEnumerable`1 filters)
at DotLiquid.Template.Render(Hash localVariables, IEnumerable`1 filters, Hash registers)
at DotLiquid.Template.RenderAndRethrowErrors(Hash hash)
at Collect_It_All.CIA_Main.booksList_SelectedIndexChanged(Object sender, EventArgs e) in D:\Documents\Dev\ezcollector\solution\Collect-It-All\CIA_Main.cs:line 298
at BrightIdeasSoftware.ObjectListView.OnSelectedIndexChanged(EventArgs e) in D:\Documents\Dev\ezcollector\solution\ObjectListView\ObjectListView.cs:line 7350
....但是,这会产生一个NullReferenceException。
Book是一个扩展Drop的类,当选择发生更改时,将在ObjectListView上调用此方法。
有人能帮我吗?
干杯,
发布于 2011-01-12 20:11:17
请提供模板和最小且可重现的测试用例。
编辑:我认为问题出在访问null索引属性(如IList)时。我已经修复了我的github分支,它也将被推送到主分支。
https://stackoverflow.com/questions/4663307
复制相似问题