Skip to content

Helper not registered first time #327

@joamla96

Description

@joamla96

I've implemented a fairly simple helper to handle if conditions.
For some reason, when i run the code first time, it ends up throwing an exception that this specific helper is not registered. If I hit the endpoint again, it works perfectly fine and continues to work fine until I restart the application, where it will then throw the exception again the first time.

Don't think it'll help, but cant hurt, the exception it throws:

HandlebarsDotNet.HandlebarsRuntimeException: Template references a helper that is not registered. Could not find helper 'ifCond'
   at HandlebarsDotNet.Compiler.HelperFunctionBinder.LateBindHelperExpression(BindingContext context, String helperName, IEnumerable`1 arguments)
   at lambda_method(Closure , TextWriter , Object )
   at HandlebarsDotNet.Compiler.DeferredSectionVisitor.RenderSection(Object value, BindingContext context, Action`2 body, Action`2 inversion)
   at lambda_method(Closure , TextWriter , Object )
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.<>c__DisplayClass7_0.<Compile>b__0(Object context)
   at FileGeneratorService.Service.GeneratePDF(VM_Quote quote) in D:\Users\jola\Source\Repos\Utility Portal\FileGeneratorService\Service.cs:line 224
   at WebAPI.Controllers.QuotesController.GetExport(Int32 id, String type) in D:\Users\jola\Source\Repos\Utility Portal\WebAPI\Controllers\QuotesController.cs:line 293
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
   at WebAPI.MiddlewareDeveloperException.Invoke(HttpContext context) in D:\Users\jola\Source\Repos\Utility Portal\WebAPI\MiddlewareDeveloperException.cs:line 23

and the helper itself:

Handlebars.RegisterHelper("ifCond", (writer, options, context, arguments) =>
{
	if (arguments[0] == null || arguments[1] == null)
	{
		options.Inverse(writer, (object)context);
		return;
	}

	if (arguments[0].ToString() == arguments[1].ToString())
	{
		options.Template(writer, (object)context);
	} else {
		options.Inverse(writer, (object)context);
	}
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions