开发者

C# DotLiquid NullReferenceException

开发者 https://www.devze.com 2023-02-03 13:25 出处:网络
I\'m using DotLiquid on the latest SVN 开发者_如何学JAVAcommit and trying the following \"easy\" code.

I'm using DotLiquid on the latest SVN 开发者_如何学JAVAcommit and trying the following "easy" code.

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 })));

The error happens in the RenderAndRethrowErrors method.

Here is a stack trace:

at 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
 ....

However this yields a NullReferenceException.

The Book is a class that extends Drop and this method is called on an ObjectListView when a selection change occurs.

Can anybody help me out here?

Cheers,


Please provide the template and a minimal and reproducable test case.

Edit: I think the problem is when accessing a null indexed property (like an IList). I've got a fix on my github fork which will be pushed to the main branch as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消