{"record":{"id":"994f6a319d50aeb0","repo":"OrchardCMS/OrchardCore","slug":"pluralforms-array-can-t-be-empty-it-must-contain-at-least-994f6a","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/StringLocalizerExtensions.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=\"IStringLocalizer\"/>.</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 LocalizedString Plural(this IStringLocalizer 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":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/StringLocalizerExtensions.cs#L20-L44","documentation":"The IStringLocalizer.Plural extension requires a non-empty array of plural forms; the first element is used as the default/singular text. An empty array cannot be localized, so the library throws immediately to fail fast instead of returning an empty LocalizedString.","triggerScenarios":"Calling localizer.Plural(count, Array.Empty<string>()) or localizer.Plural(count, new string[0], args).","commonSituations":"Building plural forms dynamically from a collection that ends up empty (e.g. a filtered list or config-driven list with no entries).","solutions":["Pass at least one plural form string (the default text) in the array.","If you have no plural variants, drop the Plural extension and index the localizer directly: localizer[\"text\", args].","Guard the array before calling: only call Plural when pluralForms.Length > 0."],"exampleFix":"// before\nlocalizer.Plural(count, Array.Empty<string>());\n// after\nlocalizer.Plural(count, new[] { \"one item\", \"{0} items\" });","handlingStrategy":"validation","validationCode":"if (pluralForms is null || pluralForms.Length == 0)\n    throw new InvalidOperationException(\"pluralForms must contain at least one entry before calling Plural.\");\nlocalizer.Plural(count, pluralForms);","typeGuard":"static bool HasPluralForms(string[]? forms) => forms is { Length: > 0 };","tryCatchPattern":"try { return localizer.Plural(count, forms); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(forms)) { return localizer[forms is { Length: > 0 } ? forms[0] : \"\"]; }","preventionTips":["Always include the default text as the first plural form.","Never pass dynamically-built form arrays without a Length check."],"tags":["localization","argument-validation","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"}