Humanizr/Humanizer · error · InvalidOperationException

Failed to generate number-to-words profile '{profile.Profile

Error message

Failed to generate number-to-words profile '{profile.ProfileName}' using engine '{profile.Engine}': {exception.Message}

What it means

This is a wrapping exception thrown during source generation by CreateProfileExpression. It catches any exception from NumberToWordsEngineContractFactory.Create and re-throws it as an InvalidOperationException that includes the profile name and engine, with the original exception preserved as InnerException. It tells you which locale profile and which engine failed, and the inner message explains the specific cause.

Source

Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/NumberToWordsProfileCatalogInput.cs:115

                builder.AppendLine();
            }

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

        static bool RequiresCulture(NumberToWordsProfileDefinition profile) =>
            GetBoolean(profile.Root, "useCulture");

        string CreateProfileExpression(NumberToWordsProfileDefinition profile, bool useCultureParameter)
        {
            try
            {
                return NumberToWordsEngineContractFactory.Create(profile, contracts, useCultureParameter);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(
                    $"Failed to generate number-to-words profile '{profile.ProfileName}' using engine '{profile.Engine}': {exception.Message}",
                    exception);
            }
        }
    }

}

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Read the {exception.Message} portion of the error — it contains the inner exception's message which identifies the actual problem (e.g. 'Missing required integer property ...').
  2. Fix the underlying locale YAML or engine contract issue indicated by the inner exception.
  3. If the inner message is unclear, check the InnerException stack trace in the build log for the exact line in the generator that threw.
  4. After fixing the root cause, rebuild to confirm all profiles emit successfully.

Example fix

// build error: Failed to generate number-to-words profile 'fr-BE' using engine 'frenchStructural': Missing required integer property 'numberToWords.feminineThreshold'

// Fix: add the missing property to the fr-BE locale YAML
numberToWords:
  engine: frenchStructural
  feminineThreshold: 100
Defensive patterns

Strategy: validation

Validate before calling

// This is a build-time error. Prevent it by validating locale YAML
// before building: ensure every numberToWords block satisfies its engine
// contract's required fields. The inner exception message in the build
// error pinpoints the exact missing or invalid property.

Prevention

When it happens

Trigger: Any inner failure during number-to-words profile code emission — e.g. error 260 (missing integer), missing required string, unsupported enum value, or a malformed YAML structure for the engine. The wrapper fires for the first profile in the build that hits such an inner error.

Common situations: A Humanizer maintainer is adding or modifying a locale and one of its engine contract members has bad or missing data. The build error shows this message; the InnerException (shown in {exception.Message}) points at the real problem.

Related errors


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