Humanizr/Humanizer · error · InvalidOperationException
Property '{propertyName}' must be an integer.
Error message
Property '{propertyName}' must be an integer. What it means
GenerationHelpers.GetRequiredInt64 (GenerationHelpers.cs:227-233) first ensures the property exists (else error 110) then requires its JSON value to be a Number that fits int64. A float, a quoted string, a boolean, or an out-of-range number fails ValueKind/TryGetInt64 and throws.
Source
Thrown at src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs:232
?? GetOptionalString(formatter.ProfileRoot, "pluralRule")
?? GetOptionalString(formatter.ProfileRoot, "resourceKeyDetector");
}
static bool GetBoolean(JsonElement element, string propertyName) =>
element.TryGetProperty(propertyName, out var valueElement) &&
valueElement.ValueKind == JsonValueKind.True;
static JsonElement GetRequiredProperty(JsonElement element, string propertyName) =>
element.TryGetProperty(propertyName, out var property)
? property
: throw new InvalidOperationException($"Missing required property '{propertyName}'.");
static long GetRequiredInt64(JsonElement element, string propertyName)
{
var property = GetRequiredProperty(element, propertyName);
return property.ValueKind == JsonValueKind.Number && property.TryGetInt64(out var value)
? value
: throw new InvalidOperationException($"Property '{propertyName}' must be an integer.");
}
static long? GetOptionalInt64(JsonElement element, string propertyName)
{
return !element.TryGetProperty(propertyName, out var property) || property.ValueKind != JsonValueKind.Number
? null
: property.TryGetInt64(out var value) ? value : null;
}
/// <summary>
/// Emits a generated <c>string[]</c> from either a plain YAML sequence or a sparse
/// numeric-slot mapping.
///
/// Supported source shapes:
///
/// 1. Plain array:
/// <code>
/// unitsMap:View on GitHub (pinned to ffc2b77c0f)
Solutions
- Make the value an integer literal with no decimal point.
- If it is a quoted string, remove the quotes so it parses as a JSON number.
- Confirm the value is within int64 range.
Example fix
// before
{ "base": "10" }
// after
{ "base": 10 } Defensive patterns
Strategy: validation
Validate before calling
// Required integer must be a JSON number fitting int64 (C#)
if (!el.TryGetProperty(name, out var p) || p.ValueKind != JsonValueKind.Number || !p.TryGetInt64(out _))
throw new InvalidOperationException($"Property '{name}' must be an integer"); Type guard
static bool IsInt64(JsonElement el, string name) =>
el.TryGetProperty(name, out var p) && p.ValueKind == JsonValueKind.Number && p.TryGetInt64(out _); Prevention
- Write integer values without decimal points so YAML/JSON keep them numeric.
- Do not quote integers as strings.
- Validate numeric ranges where int64 is assumed.
When it happens
Trigger: A required integer property holds a JSON float (1.5), a string ("5"), true/false, or a number too large for int64.
Common situations: YAML number parsed as a float due to a decimal point; value quoted as a string; locale data authored with a numeric-looking string.
Related errors
- Indexed string arrays require string values. Property '{prop
- Expected JSON object.
- Missing required property '{sourcePath}'.
- Missing required property '{propertyName}'.
- Expected JSON array.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/97a0f3aac428c20b.
Report an issue: GitHub.