OrchardCMS/OrchardCore · error · ArgumentException
PluralForms array can't be empty, it must contain at least…
Error message
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.
What it means
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.
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.
Example fix
// before
localizer.Plural(count, Array.Empty<string>());
// after
localizer.Plural(count, new[] { "one item", "{0} items" }); Defensive patterns
Strategy: validation
Validate before calling
if (pluralForms is null || pluralForms.Length == 0)
throw new InvalidOperationException("pluralForms must contain at least one entry before calling Plural.");
localizer.Plural(count, pluralForms); Type guard
static bool HasPluralForms(string[]? forms) => forms is { Length: > 0 }; Try / catch
try { return localizer.Plural(count, forms); }
catch (ArgumentException ex) when (ex.ParamName == nameof(forms)) { return localizer[forms is { Length: > 0 } ? forms[0] : ""]; } Prevention
- Always include the default text as the first plural form.
- Never pass dynamically-built form arrays without a Length check.
When it happens
Trigger: Calling localizer.Plural(count, Array.Empty<string>()) or localizer.Plural(count, new string[0], args).
Common situations: Building plural forms dynamically from a collection that ends up empty (e.g. a filtered list or config-driven list with no entries).
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- PluralForms array can't be empty, it must contain at least…
- Plural form ' ' doesn't exist for the key ' ' in the ' '…
- MessageId can't be empty.
- PluralForms array can't be empty, it must contain at least…
- The calendar is not supported.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/994f6a319d50aeb0.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/StringLocalizerExtensions.cs:38
ArgumentNullException.ThrowIfNull(plural);
return localizer[singular, new PluralizationArgument { Count = count, Forms = [singular, plural], Arguments = arguments }];
}
/// <summary>
/// Gets the pluralization form.
/// </summary>
/// <param name="localizer">The <see cref="IStringLocalizer"/>.</param>
/// <param name="count">The number to be used for selecting the pluralization form.</param>
/// <param name="pluralForms">A list of pluralization forms.</param>
/// <param name="arguments">The parameters used in the key.</param>
public static LocalizedString Plural(this IStringLocalizer localizer, int count, string[] pluralForms, params object[] arguments)
{
ArgumentNullException.ThrowIfNull(pluralForms);
if (pluralForms.Length == 0)
{
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));
}
return localizer[pluralForms[0], new PluralizationArgument { Count = count, Forms = pluralForms, Arguments = arguments }];
}
}
View on GitHub (pinned to 4306c0717f)