{"record":{"id":"1542cc2fbf8235e9","repo":"OrchardCMS/OrchardCore","slug":"pluralforms-array-can-t-be-empty-it-must-contain-at-least","errorCode":null,"errorMessage":"PluralForms array can't be empty, it must contain at least one element. If you don't want to specify the plural text, use IStringLocalizer without Plural extension.","messagePattern":"PluralForms array can't be empty, it must contain at least one element\\. If you don't want to specify the plural text, use IStringLocalizer without Plural extension\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/HtmlLocalizerExtensions.cs","lineNumber":38,"sourceCode":"        ArgumentNullException.ThrowIfNull(plural);\n\n        return localizer[singular, new PluralizationArgument { Count = count, Forms = [singular, plural], Arguments = arguments }];\n    }\n\n    /// <summary>\n    /// Gets the pluralization form.\n    /// </summary>\n    /// <param name=\"localizer\">The <see cref=\"IHtmlLocalizer\"/>.</param>\n    /// <param name=\"count\">The number to be used for selecting the pluralization form.</param>\n    /// <param name=\"pluralForms\">A list of pluralization forms.</param>\n    /// <param name=\"arguments\">The parameters used in the key.</param>\n    public static LocalizedHtmlString Plural(this IHtmlLocalizer localizer, int count, string[] pluralForms, params object[] arguments)\n    {\n        ArgumentNullException.ThrowIfNull(pluralForms);\n\n        if (pluralForms.Length == 0)\n        {\n            throw new ArgumentException(\"PluralForms array can't be empty, it must contain at least one element. If you don't want to specify the plural text, use IStringLocalizer without Plural extension.\", nameof(pluralForms));\n        }\n\n        var name = pluralForms[0];\n\n        return localizer[name, new PluralizationArgument { Count = count, Forms = pluralForms, Arguments = arguments }];\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/HtmlLocalizerExtensions.cs#L20-L46","documentation":"The HTML localizer Plural extension requires at least one plural form string to derive the resource name and forms list. Passing an empty array gives the localizer nothing to look up, so the extension validates length > 0 and throws ArgumentException pointing at pluralForms, hinting that the non-array IStringLocalizer Plural should be used instead.","triggerScenarios":"Calling localizer.Plural(count, new string[0]) or Plural(count, forms) where forms was built dynamically and ended up empty — checked right after ArgumentNullException.ThrowIfNull in the extension.","commonSituations":"Constructing plural forms from configuration or database rows that returned no rows, over-nullable refactoring producing empty arrays, or misusing the API when only a count and default text are available.","solutions":["Ensure the pluralForms array has at least one entry before calling; the first element is used as the resource name.","If you only have a count and default text, use the string/array-literal overloads of Plural or IStringLocalizer's plural extension instead of an empty array.","Guard the caller: if forms.Length == 0, fall back to localizer[defaultText, count]."],"exampleFix":"// before\nvar html = localizer.Plural(count, Array.Empty<string>());\n// after\nvar html = localizer.Plural(count, new[] { \"{0} item\", \"{0} items\" });","handlingStrategy":"validation","validationCode":"if (pluralForms is null || pluralForms.Length == 0)\n    return localizer[defaultText, count]; // fallback before calling Plural","typeGuard":"bool HasPluralForms(string[]? forms) => forms is { Length: > 0 };","tryCatchPattern":"try { html = localizer.Plural(count, forms); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(forms)) { html = localizer[defaultText, count]; }","preventionTips":["Never pass arrays built from external data without a length check","Use the literal-array overload when forms are known at compile time","Centralize plural calls in a helper that validates forms"],"tags":["localization","pluralization","argument-validation","razor"],"backgroundTag":"empty-required-field","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}