{"record":{"id":"f51dedf5fd34b3d7","repo":"microsoft/semantic-kernel","slug":"a-helper-with-the-name-helpername-is-already-r","errorCode":null,"errorMessage":"A helper with the name '{helperName}' is already registered.","messagePattern":"A helper with the name '(.+?)' is already registered\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelperUtils.cs","lineNumber":26,"sourceCode":"\nnamespace Microsoft.SemanticKernel.PromptTemplates.Handlebars.Helpers;\n\n/// <summary>\n/// Extension class to register additional helpers as Kernel System helpers.\n/// </summary>\ninternal static class KernelHelpersUtils\n{\n    /// <summary>\n    /// Registers a helper with the Handlebars instance, throwing an exception if a helper with the same name is already registered.\n    /// </summary>\n    /// <param name=\"handlebarsInstance\">The <see cref=\"IHandlebars\"/>-instance.</param>\n    /// <param name=\"helperName\">The name of the helper.</param>\n    /// <param name=\"helper\">The helper to register.</param>\n    internal static void RegisterHelperSafe(IHandlebars handlebarsInstance, string helperName, HandlebarsReturnHelper helper)\n    {\n        if (handlebarsInstance.Configuration.Helpers.ContainsKey(helperName))\n        {\n            throw new InvalidOperationException($\"A helper with the name '{helperName}' is already registered.\");\n        }\n\n        handlebarsInstance.RegisterHelper(helperName, helper);\n    }\n\n    /// <summary>\n    /// Returns value if defined, else, tries to resolve value from given KernelArguments dictionary.\n    /// </summary>\n    /// <param name=\"argument\">Argument to process.</param>\n    /// <param name=\"kernelArguments\">Dictionary of variables maintained by the Handlebars context.</param>\n    internal static object? GetArgumentValue(object argument, KernelArguments kernelArguments)\n    {\n        // If the argument is of type UndefinedBindingResult, it means that Handlebars attempted to retrieve the value for a binding \n        // but was unable to do so because the variable was not defined or not passed to the template context at the time of render.\n        // Thus, we try to get the value from the kernel arguments dictionary.\n        if (argument is UndefinedBindingResult result)\n        {\n            return kernelArguments.TryGetValue(result.Value, out var variable) ? variable : null;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelperUtils.cs#L8-L44","documentation":"Thrown when attempting to register a Handlebars helper whose name already exists in the Handlebars configuration's Helpers dictionary. RegisterHelperSafe guards against silent overwrites of existing helpers.","triggerScenarios":"KernelHelpersUtils.RegisterHelperSafe is called with a helperName that already has an entry in handlebarsInstance.Configuration.Helpers, e.g., registering the same helper twice or using a name that collides with a built-in.","commonSituations":"Registering a custom helper with a name that clashes with a system helper (e.g., 'message'), re-registering helpers across multiple initialization calls without checking existence, or plugin name collisions.","solutions":["Choose a unique helper name (prefix with your plugin/namespace) to avoid collisions.","Before registering, check handlebarsInstance.Configuration.Helpers.ContainsKey(name) and skip or replace deliberately.","Initialize helpers only once per Handlebars instance lifetime."],"exampleFix":"// before\nKernelHelpersUtils.RegisterHelperSafe(handlebars, \"message\", helper);\nKernelHelpersUtils.RegisterHelperSafe(handlebars, \"message\", other); // throws\n// after\nif (!handlebars.Configuration.Helpers.ContainsKey(\"myPlugin_message\"))\n{\n    KernelHelpersUtils.RegisterHelperSafe(handlebars, \"myPlugin_message\", helper);\n}","handlingStrategy":"validation","validationCode":"if (handlebars.Configuration.Helpers.ContainsKey(helperName))\n    throw new InvalidOperationException($\"Helper '{helperName}' already registered; choose a unique name.\");\nKernelHelpersUtils.RegisterHelperSafe(handlebars, helperName, helper);","typeGuard":"public static bool IsHelperRegistered(IHandlebars handlebars, string name) =>\n    handlebars.Configuration.Helpers.ContainsKey(name);","tryCatchPattern":"try\n{\n    KernelHelpersUtils.RegisterHelperSafe(handlebars, name, helper);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"already registered\"))\n{\n    _logger.LogWarning(\"Helper '{Name}' already registered; skipping.\", name);\n}","preventionTips":["Namespace-prefix custom helper names to avoid collisions.","Check Helpers.ContainsKey before registering.","Initialize helpers once per Handlebars instance."],"tags":["handlebars","prompt-templates","helper-registration","duplicate"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}