Humanizr/Humanizer · error · InvalidOperationException
Inverted tens token '{property.Name}' must map to an integer
Error message
Inverted tens token '{property.Name}' must map to an integer value. What it means
Thrown while building an InvertedTensToken[] when the YAML node is a mapping but one of its values is not an integer. The builder maps each token name to an integer base value; a non-numeric value (or a number that fails TryGetInt64) cannot be turned into the token's numeric component.
Source
Thrown at src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs:1227
}
static string CreateInvertedTensTokenArrayExpression(JsonElement arrayElement)
{
if (arrayElement.ValueKind is not (JsonValueKind.Array or JsonValueKind.Object))
{
throw new InvalidOperationException("Expected JSON array or mapping.");
}
var builder = new StringBuilder("new InvertedTensToken[] { ");
var first = true;
if (arrayElement.ValueKind == JsonValueKind.Object)
{
foreach (var (Name, Value) in arrayElement.EnumerateObject()
.Select(static property =>
{
return property.Value.ValueKind != JsonValueKind.Number || !property.Value.TryGetInt64(out var value)
? throw new InvalidOperationException($"Inverted tens token '{property.Name}' must map to an integer value.")
: (property.Name, Value: value);
})
.OrderByDescending(static entry => entry.Value)
.ThenBy(static entry => entry.Name, StringComparer.Ordinal))
{
if (!first)
{
builder.Append(", ");
}
builder.Append("new(");
builder.Append(QuoteLiteral(Name));
builder.Append(", ");
builder.Append(Value.ToString(CultureInfo.InvariantCulture));
builder.Append(')');
first = false;
}
}View on GitHub (pinned to ffc2b77c0f)
Solutions
- In the inverted-tens mapping, set each token's value to an integer literal (no quotes): einundzwanzig: 21.
- Ensure no value is a string, boolean, or decimal that cannot be parsed as int64.
- Rebuild; the generator will name the first offending token if others remain.
Example fix
# before invertedTens: einundzwanzig: 'einundzwanzig' # after invertedTens: einundzwanzig: 21
Defensive patterns
Strategy: validation
Validate before calling
# For every key in the inverted-tens mapping, the value must be an integer. # rg -B1 -A1 "invertedTens" src/Humanizer/Locales/<code>.yml # Each token line should read '<token>: <integer>' with an unquoted number.
Prevention
- Always use unquoted integer values for inverted-tens token magnitudes.
- Never reuse the token word as its own value.
- Build locally so the generator names the first offending token.
When it happens
Trigger: A locale YAML defines the inverted-tens section as a mapping where at least one entry's value is a string, boolean, or a non-integer number. The Select lambda checks ValueKind and TryGetInt64, then throws naming the offending property (the token string).
Common situations: A contributor adds a token but leaves its value as a word (e.g. 'einundzwanzig: einundzwanzig') instead of the integer 21, or uses a float. The build-time generator output names the specific token that is wrong.
Related errors
- Billion-word cardinal strategy requires a singular billion w
- Billion-word cardinal strategy requires a plural billion wor
- Property '{propertyName}' must be a string, array, or mappin
- Property '{propertyName}' must be a mapping.
- Expected JSON array or mapping.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/d1cae9fa3f11a974.
Report an issue: GitHub.