Humanizr/Humanizer · error · ArgumentException

Unrecognized number word: {unrecognizedWord}

Error message

Unrecognized number word: {unrecognizedWord}

What it means

LinkingAffixWordsToNumberConverter.Convert throws this ArgumentException after TryConvert reports the first token it could not map. It serves languages whose compounds embed teen stems or joined cardinal suffixes, so a token outside the locale's cardinal/linked-suffix map is unrecoverable. Only the throwing Convert path raises it; TryConvert returns false with the offending token in the out parameter.

Source

Thrown at src/Humanizer/Localisation/WordsToNumber/LinkingAffixWordsToNumberConverter.cs:16

namespace Humanizer;

/// <summary>
/// Parses languages that use linking affixes inside compounds, such as embedded teen stems or
/// joined suffixes on cardinal tokens.
/// </summary>
internal class LinkingAffixWordsToNumberConverter(LinkingAffixWordsToNumberProfile profile) : GenderlessWordsToNumberConverter
{
    readonly LinkingAffixWordsToNumberProfile profile = profile;

    /// <inheritdoc />
    public override long Convert(string words)
    {
        if (!TryConvert(words, out var parsedValue, out var unrecognizedWord))
        {
            throw new ArgumentException($"Unrecognized number word: {unrecognizedWord}");
        }

        return parsedValue;
    }

    /// <inheritdoc />
    public override bool TryConvert(string words, out long parsedValue) =>
        TryConvert(words, out parsedValue, out _);

    /// <inheritdoc />
    public override bool TryConvert(string words, out long parsedValue, out string? unrecognizedWord)
    {
        if (string.IsNullOrWhiteSpace(words))
        {
            throw new ArgumentException("Input words cannot be empty.");
        }

        var normalized = TokenMapWordsToNumberNormalizer.Normalize(

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Switch from ToNumber to TryToNumber(words, out var n, culture, out var unrecognized) and handle the false return.
  2. Inspect the reported unrecognizedWord to find the misspelled or foreign token and correct the input.
  3. Confirm the CultureInfo passed matches the language of the phrase (registry falls back to English for unsupported locales).
  4. Pre-clean input (trim, collapse spaces, replace typographic quotes) before parsing.

Example fix

// before
var n = "twenty banana".ToNumber(CultureInfo.GetCultureInfo("en"));
// after
if ("twenty banana".TryToNumber(out var n, CultureInfo.GetCultureInfo("en"), out var bad))
    Console.WriteLine(n);
else
    Console.WriteLine($"bad token: {bad}");
Defensive patterns

Strategy: validation

Validate before calling

// Use the non-throwing overload; it reports the first bad token.
if (!words.TryToNumber(out var n, culture, out var unrecognized))
    return Result.Fail($"unrecognized token: {unrecognized}");
return Result.Ok(n);

Try / catch

// Only if you must call ToNumber:
try { var n = words.ToNumber(culture); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Unrecognized number word"))
    { /* handle unknown token */ }

Prevention

When it happens

Trigger: Calling ToNumber(words, culture) (or the converter's Convert) with a phrase whose normalized tokens are not in the locale's linking-affix cardinal map, e.g. a misspelled word, a number from a different locale, or stray punctuation the normalizer does not strip. The throw is produced at line 16 when TryConvert returns false.

Common situations: User-typed free text passed straight into ToNumber; a locale mismatch where English words are parsed under a linking-affix locale (or vice versa); copy-paste with smart quotes or extra tokens; an ordinal/decimal phrase fed to the integer converter.

Related errors


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/0c6565aee778fec9. Report an issue: GitHub.