3

I'm trying to use the following template (TestTemplate) in a console application using .NET Core 2.1 and Handlebars.Net 1.9.5

<html>
<head>
    <title>A title</title>
</head>

<body>
    {{ > (lookup TemplateName)}}
</body>
</html>

So the line with {{ > (lookup TemplateName)}} is causing me problems.

The idea is to use a partial, where the partial name will be resolved later by passing the TemplateName variable.

However, when I try to compile the template by using

var foo = Resource1.TestTemplate;
Handlebars.Compile(Encoding.UTF8.GetString(foo));

I get the following exception :

System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type. at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags) at HandlebarsDotNet.Compiler.SubExpressionVisitor.GetHelperDelegateFromMethodCallExpression(MethodCallExpression helperCall) at HandlebarsDotNet.Compiler.SubExpressionVisitor.VisitSubExpression(SubExpressionExpression subex) at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node) at System.Linq.Expressions.ConditionalExpression.Accept(ExpressionVisitor visitor) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block) at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node) at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor) at HandlebarsDotNet.Compiler.FunctionBuilder.Compile(IEnumerable1 expressions, Expression parentContext, String templatePath) --- End of inner exception stack trace --- at HandlebarsDotNet.Compiler.FunctionBuilder.Compile(IEnumerable1 expressions, Expression parentContext, String templatePath) at HandlebarsDotNet.Compiler.FunctionBuilder.Compile(IEnumerable1 expressions, String templatePath) --- End of inner exception stack trace --- at HandlebarsDotNet.Compiler.FunctionBuilder.Compile(IEnumerable1 expressions, String templatePath) at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.Compile(String template)

I hope someone has an idea, because I've already been searching quite some time.

1 Answer 1

2

Ok I totally missed that I was looking at the HandleBars.js documentation.

In HandleBars.js the lookup helper is built-in, but so far, it isn't in the .net version.

So you have to declare the lookup helper yourself, which in my case goes something like this:

Handlebars.RegisterHelper("lookup", (output, context, arguments) => { output.WriteSafeString(arguments[0]); }); 

Hope it can help someone else.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for adding this! Would love to see a PR submitted to add it to the core library, as well. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.