{"record":{"id":"5e39080f0fd98ab6","repo":"OrchardCMS/OrchardCore","slug":"pluralforms-array-can-t-be-empty-it-must-contain-at-least-5e3908","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/ViewLocalizerExtensions.cs","lineNumber":39,"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=\"IViewLocalizer\"/>.</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 IViewLocalizer 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        return localizer[pluralForms[0], new PluralizationArgument { Count = count, Forms = pluralForms, Arguments = arguments }];\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":45,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/ViewLocalizerExtensions.cs#L21-L45","documentation":"The IViewLocalizer.Plural extension mirrors the IStringLocalizer.Plural overload for HTML views and likewise requires at least one plural form. The first element of the array is the base text that gets localized; an empty array would produce nothing renderable, so it throws ArgumentException.","triggerScenarios":"Calling localizer.Plural(count, Array.Empty<string>(), args) or an empty string[] from a variable when rendering an HTML view.","commonSituations":"View code that assembles plural forms from a model or settings collection which is empty at render time.","solutions":["Provide at least the base string as the first plural form.","Use the non-plural localizer call (localizer[Html.Create(...)]) if no plural forms are needed.","Validate pluralForms.Length > 0 before invoking Plural in the view."],"exampleFix":"// before\nT.Plural(count, emptyForms)\n// after\nT.Plural(count, new[] { \"one comment\", \"{0} comments\" })","handlingStrategy":"validation","validationCode":"if (forms is null || forms.Length == 0)\n{\n    // fall back to non-plural localization\n    return localizer[Html.Raw(\"\")];\n}\nlocalizer.Plural(count, forms);","typeGuard":"static bool HasPluralForms(string[]? forms) => forms is { Length: > 0 };","tryCatchPattern":"try { return T.Plural(count, forms); }\ncatch (ArgumentException) { return T[forms?.FirstOrDefault() ?? string.Empty]; }","preventionTips":["Define plural form literals inline in views instead of building them from possibly-empty collections.","Prefer the non-plural T[...] indexer when only one text variant exists."],"tags":["localization","razor-views","pluralization"],"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-16T04:17:20.429Z"}