Humanizr/Humanizer · error · InvalidOperationException

Missing required integer property

Error message

Missing required integer property '{member.SourcePath}'.

What it means

Thrown during source generation by GetInt64Value when a number-to-words engine contract declares a required integer member, but the locale YAML neither provides that property as a JSON number at the member's SourcePath nor defines a DefaultValue fallback. The generator cannot emit a valid constructor argument for the converter, so it halts code emission with this message naming the missing SourcePath.

Solutions

  1. Open the locale YAML file referenced by the build error and add the missing integer property at the path indicated by {member.SourcePath} in the numberToWords block.
  2. If the property should be optional, set a DefaultValue on the EngineContractMember in the engine contract definition so the generator has a fallback.
  3. Verify the YAML indentation so the integer lands under the correct engine sub-object — a mis-indented scalar can appear as a missing property.
  4. Run a clean rebuild (dotnet build) after fixing the YAML to confirm the source generator emits successfully.

Example fix

// locale YAML — before
numberToWords:
  engine: englishStructural
  // missing required integer property 'feminineThreshold'

// after
numberToWords:
  engine: englishStructural
  feminineThreshold: 100
Defensive patterns

Strategy: validation

Validate before calling

// Before building, validate that every locale YAML numberToWords block
// includes all required integer properties declared by its engine contract.
// Cross-check the engine contract JSON in EngineContractCatalog for
// members with kind 'int32'/'int64' and no defaultValue, then confirm the
// locale YAML has those keys as numeric values.

Prevention

When it happens

Trigger: Adding or editing a locale YAML under src/Humanizer/Locales whose numberToWords engine is bound to a structural contract (in EngineContractCatalog) that has an int32/int64 member. The locale omits the required integer field (or provides a non-numeric value such as a string or null), and the contract member has no DefaultValue set.

Common situations: A Humanizer maintainer adds a new locale or updates an existing locale's numberToWords block and forgets a required integer property (e.g. a threshold, offset, or mode flag). Also triggered when renaming a property in the engine contract JSON without updating all locale YAML files that use that engine.

Related errors


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

Appendix: source

Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/NumberToWordsEngineContractFactory.cs:600

            return bool.TryParse(member.DefaultValue, out var defaultValue) && defaultValue;
        }

        static long GetInt64Value(JsonElement root, EngineContractMember member)
        {
            if (EngineContractUtilities.TryGetElement(root, member.SourcePath, out var value) &&
                value.ValueKind == JsonValueKind.Number &&
                value.TryGetInt64(out var number))
            {
                return number;
            }

            if (member.DefaultValue is not null && long.TryParse(member.DefaultValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
            {
                return number;
            }

            throw new InvalidOperationException($"Missing required integer property '{member.SourcePath}'.");
        }

        static long? GetOptionalInt64Value(JsonElement root, EngineContractMember member)
        {
            if (EngineContractUtilities.TryGetElement(root, member.SourcePath, out var value) &&
                value.ValueKind == JsonValueKind.Number &&
                value.TryGetInt64(out var number))
            {
                return number;
            }

            return member.DefaultValue is not null &&
                   long.TryParse(member.DefaultValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out number)
                ? number
                : null;
        }

    }

View on GitHub (pinned to ffc2b77c0f)