Humanizr/Humanizer · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values. (Pa
Error message
Specified argument was out of the range of valid values. (Parameter 'items')
What it means
Thrown by EnglishArticle.AppendArticlePrefix when the input string array is empty (items.Length == 0). The method is designed to sort article-prefixed strings; an empty array has nothing to sort so Humanizer treats it as a programming error and throws ArgumentOutOfRangeException with the parameter name 'items'.
Source
Thrown at src/Humanizer/ArticlePrefixSort.cs:17
namespace Humanizer;
/// <summary>
/// Contains methods for removing, appending and prepending article prefixes for sorting strings ignoring the article.
/// </summary>
public static class EnglishArticle
{
/// <summary>
/// Removes the prefixed article and appends it to the same string.
/// </summary>
/// <param name="items">The input array of strings</param>
/// <returns>Sorted string array</returns>
public static string[] AppendArticlePrefix(string[] items)
{
if (items.Length == 0)
{
throw new ArgumentOutOfRangeException(nameof(items));
}
var transformed = new string[items.Length];
for (var i = 0; i < items.Length; i++)
{
var item = items[i]
.AsSpan();
if (TryGetArticlePrefixLength(item, out var articleLength))
{
var removed = item[articleLength..]
.TrimStart();
var article = item[..articleLength];
transformed[i] = $"{removed} {article}";
}
else
{
transformed[i] = itemView on GitHub (pinned to ffc2b77c0f)
Solutions
- Check items.Length > 0 before calling AppendArticlePrefix.
- If an empty input is a valid no-op in your context, return an empty array early instead of calling the method.
- Ensure the upstream data source (split, filter, query) is not unexpectedly empty.
Example fix
// before
var sorted = EnglishArticle.AppendArticlePrefix(titles.ToArray());
// after
if (titles.Count == 0)
return Array.Empty<string>();
var sorted = EnglishArticle.AppendArticlePrefix(titles.ToArray()); Defensive patterns
Strategy: validation
Validate before calling
if (items is null || items.Length == 0)
return Array.Empty<string>();
return EnglishArticle.AppendArticlePrefix(items); Prevention
- Always check items.Length > 0 before calling AppendArticlePrefix.
- Handle the empty case as a no-op in the calling code rather than relying on the exception.
- Guard upstream data sources (split, filter, query) against returning empty collections.
When it happens
Trigger: Calling EnglishArticle.AppendArticlePrefix(items) where items is a zero-length string array. This typically happens when the array was constructed from a filtered or split result that produced no elements.
Common situations: A developer splits a string by a delimiter and passes the result to AppendArticlePrefix without checking for emptiness. Or a LINQ query that filters a collection returns zero items and the result is passed directly.
Related errors
- The value must be finite and fit the range supported by Byte
- Unknown number-to-words profile.
- Unknown ordinal date profile.
- Unknown ordinalizer profile.
- Unknown clock-notation profile.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/33adaac11473463b.
Report an issue: GitHub.