Humanizr/Humanizer · error · NotSupportedException
Grammatical case is not supported for time-unit symbols.
Error message
Grammatical case is not supported for time-unit symbols.
What it means
Thrown by DefaultHumanizeCore when both toSymbols is true and a grammaticalCase is specified. Time-unit symbols (e.g. "1h", "30m") are abbreviations that do not inflect by grammatical case, so requesting a case alongside symbols is logically contradictory.
Source
Thrown at src/Humanizer/TimeSpanHumanizeExtensions.cs:652
TimeSpan timeSpan,
int precision,
bool countEmptyUnits,
CultureInfo? culture,
TimeUnit maxUnit,
TimeUnit minUnit,
string? collectionSeparator,
bool toWords,
bool toSymbols,
GrammaticalCase? grammaticalCase)
{
if (grammaticalCase is { } requestedCase)
{
ValidateGrammaticalCase(requestedCase);
}
if (toSymbols && grammaticalCase is not null)
{
throw new NotSupportedException("Grammatical case is not supported for time-unit symbols.");
}
if (precision == 1 && !countEmptyUnits)
{
return HumanizeSinglePart(timeSpan, culture, maxUnit, minUnit, toWords, toSymbols, grammaticalCase);
}
var timeParts = CreatePrecisionLimitedTimeParts(
timeSpan,
culture,
maxUnit,
minUnit,
precision,
countEmptyUnits,
toWords,
toSymbols,
grammaticalCase);
View on GitHub (pinned to ffc2b77c0f)
Solutions
- Do not combine toSymbols=true with a grammaticalCase; choose words (toWords) for case support.
- Set grammaticalCase to null when using symbols.
- Split the call: use symbols without case, or words with case.
Example fix
// before var s = ts.HumanizeWithCase(GrammaticalCase.Genitive, precision: 1, toSymbols: true); // after var s = ts.HumanizeWithCase(GrammaticalCase.Genitive, precision: 1); // symbols are not requested; words support case inflection
Defensive patterns
Strategy: validation
Validate before calling
static void AssertSymbolCaseCompat(bool toSymbols, GrammaticalCase? grammaticalCase)
{
if (toSymbols && grammaticalCase is not null)
throw new InvalidOperationException("Symbols and grammatical case are mutually exclusive.");
} Prevention
- Never pass both toSymbols=true and a grammaticalCase.
- Use words (toWords=true) when you need case inflection.
- Document the mutual exclusivity in your API wrapper.
When it happens
Trigger: Calling a humanize overload that sets toSymbols=true while also passing a non-null grammaticalCase. This can happen indirectly through HumanizeWithCase when the code path routes to symbol output.
Common situations: Developer combines toSymbols and grammaticalCase in the same call expecting case-aware abbreviations. Misunderstanding that symbols are case-invariant. Passing both parameters from a configuration object.
Related errors
- The configured ITimeSpanHumanizeStrategy does not support gr
- The formatter for '{culture?.Name ?? CultureInfo.CurrentCult
- Custom strategy type '{GetType().FullName}' must explicitly
- Custom formatter type '{GetType().FullName}' must explicitly
- Culture '{Culture.Name}' has no grammatical-case classificat
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/79bd7a05de065eba.
Report an issue: GitHub.