Humanizr/Humanizer · error · InvalidOperationException

A property path is required.

Error message

A property path is required.

What it means

EngineContractUtilities.GetLeafPropertyName (EngineContractUtilities.cs:45-55) extracts the last segment of a dot-path and throws when the path is null/empty/whitespace. This is a contract-authoring error: a member that needs a generated property name was given no sourcePath to derive it from.

Source

Thrown at src/Humanizer.SourceGenerators/Common/EngineContractUtilities.cs:49

        }

        public static bool TryGetOptionalString(JsonElement root, string? sourcePath, out string? value)
        {
            if (TryGetElement(root, sourcePath, out var property) && property.ValueKind == JsonValueKind.String)
            {
                value = property.GetString();
                return true;
            }

            value = null;
            return false;
        }

        public static string GetLeafPropertyName(string? sourcePath)
        {
            if (string.IsNullOrWhiteSpace(sourcePath))
            {
                throw new InvalidOperationException("A property path is required.");
            }

            var path = sourcePath!;
            var lastSeparator = path.LastIndexOf('.');
            return lastSeparator >= 0 ? path.Substring(lastSeparator + 1) : path;
        }
    }
}

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Provide a concrete non-empty sourcePath for the member.
  2. If the member no longer needs a source-derived name, refactor the contract so GetLeafPropertyName is not called for it.

Example fix

// before
{ "sourcePath": "" }
// after
{ "sourcePath": "numbers.unitsMap" }
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a non-empty sourcePath when a leaf name is needed (C#)
if (string.IsNullOrWhiteSpace(member.SourcePath))
    throw new InvalidOperationException("Contract member requires a non-empty sourcePath to derive a property name");

Prevention

When it happens

Trigger: An engine-contract member has an empty or null sourcePath but the generator still needs to compute a leaf property name from it.

Common situations: Refactoring a contract member to inline data while leaving sourcePath empty; copying a member and deleting its sourcePath without adjusting how its name is derived.

Related errors


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