Humanizr/Humanizer · error · ArgumentOutOfRangeException

Unknown words-to-number profile.

Error message

Unknown words-to-number profile.

What it means

This message is emitted into generated source code (WordsToNumberProfileCatalog.g.cs) as the default case of the Resolve switch. At runtime, WordsToNumberProfileCatalog.Resolve(kind) throws ArgumentOutOfRangeException when the kind string does not match any compiled words-to-number profile name. Only locales whose wordsToNumber feature was registered as generated appear in the catalog.

Source

Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/WordsToNumberProfileCatalogInput.cs:72

            builder.AppendLine();
            builder.AppendLine("static partial class WordsToNumberProfileCatalog");
            builder.AppendLine("{");
            builder.AppendLine("    public static IWordsToNumberConverter Resolve(string kind)");
            builder.AppendLine("    {");
            builder.AppendLine("        switch (kind)");
            builder.AppendLine("        {");

            foreach (var profile in profiles.OrderBy(static profile => profile.ProfileName, StringComparer.Ordinal))
            {
                builder.Append("            case ");
                builder.Append(QuoteLiteral(profile.ProfileName));
                builder.Append(": return ");
                builder.Append(GetCatalogPropertyName(profile.ProfileName));
                builder.AppendLine(";");
            }

            builder.AppendLine("        }");
            builder.AppendLine("        throw new ArgumentOutOfRangeException(nameof(kind), kind, \"Unknown words-to-number profile.\");");
            builder.AppendLine("    }");
            builder.AppendLine();

            foreach (var profile in profiles.OrderBy(static profile => profile.ProfileName, StringComparer.Ordinal))
            {
                AppendLazyCachedMember(
                    builder,
                    "    ",
                    "static",
                    "IWordsToNumberConverter",
                    GetCatalogPropertyName(profile.ProfileName),
                    WordsToNumberEngineContractFactory.Create(profile));
                builder.AppendLine();
            }

            builder.AppendLine("}");
            context.AddSource("WordsToNumberProfileCatalog.g.cs", SourceText.From(builder.ToString(), Encoding.UTF8));
        }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Verify the target locale has a wordsToNumber YAML block with a matching profile name under src/Humanizer/Locales.
  2. Ensure the wordsToNumber feature is registered with UsesGeneratedProfile: true.
  3. Fall back to a known-supported locale (e.g. 'en') if the requested locale is unsupported.
  4. Confirm the culture name matches exactly the compiled profile name.

Example fix

// before — 'xx' has no words-to-number profile
var number = "five".ToNumber(new CultureInfo("xx"));

// after — use a supported locale
var number = "five".ToNumber(new CultureInfo("en"));
Defensive patterns

Strategy: validation

Validate before calling

// Before calling a words-to-number API with an arbitrary locale, verify support.
var culture = new CultureInfo("en");
// Guard if calling the internal catalog directly.

Try / catch

try
{
    var converter = WordsToNumberProfileCatalog.Resolve(kind);
}
catch (ArgumentOutOfRangeException)
{
    converter = WordsToNumberProfileCatalog.Resolve("en");
}

Prevention

When it happens

Trigger: Calling a words-to-number API with a culture whose words-to-number profile name is not compiled into the catalog. The locale may be missing a wordsToNumber block, or the profile name may not match the kind string being passed.

Common situations: A consumer requests words-to-number parsing for an unsupported locale. A developer working on words-to-number locale parity passes an unfinished profile name during testing.

Related errors


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