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 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.
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.
Example fix
// before
T.Plural(count, emptyForms)
// after
T.Plural(count, new[] { "one comment", "{0} comments" }) Defensive patterns
Strategy: validation
Validate before calling
if (forms is null || forms.Length == 0)
{
// fall back to non-plural localization
return localizer[Html.Raw("")];
}
localizer.Plural(count, forms); Type guard
static bool HasPluralForms(string[]? forms) => forms is { Length: > 0 }; Try / catch
try { return T.Plural(count, forms); }
catch (ArgumentException) { return T[forms?.FirstOrDefault() ?? string.Empty]; } Prevention
- 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.
When it happens
Trigger: Calling localizer.Plural(count, Array.Empty<string>(), args) or an empty string[] from a variable when rendering an HTML view.
Common situations: View code that assembles plural forms from a model or settings collection which is empty at render time.
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
- Plural form ' ' doesn't exist for the key ' ' in the ' '…
- PluralForms array can't be empty, it must contain at least…
- PluralForms array can't be empty, it must contain at least…
- The calendar is not supported.
- MessageId can't be empty.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/5e39080f0fd98ab6.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/ViewLocalizerExtensions.cs:39
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="IViewLocalizer"/>.</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 LocalizedHtmlString Plural(this IViewLocalizer 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)