AvaloniaUI/Avalonia · error · FormatException
Invalid text trimming string: '{s}'.
Error message
Invalid text trimming string: '{s}'. What it means
Thrown by TextTrimming.Parse when the input string does not match any known text-trimming mode. Avalonia recognizes the named enum values None, CharacterEllipsis, WordEllipsis, PrefixCharacterEllipsis, and PathSegmentEllipsis (matched by name). Any other string is treated as a malformed trimming specification and rejected with a FormatException.
Source
Thrown at src/Avalonia.Base/Media/TextTrimming.cs:85
}
if (Matches(nameof(CharacterEllipsis)))
{
return CharacterEllipsis;
}
else if (Matches(nameof(WordEllipsis)))
{
return WordEllipsis;
}
else if (Matches(nameof(PrefixCharacterEllipsis)))
{
return PrefixCharacterEllipsis;
}
else if (Matches(nameof(PathSegmentEllipsis)))
{
return PathSegmentEllipsis;
}
throw new FormatException($"Invalid text trimming string: '{s}'.");
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Use one of the exact recognized names: None, CharacterEllipsis, WordEllipsis, PrefixCharacterEllipsis, or PathSegmentEllipsis.
- Trim whitespace and verify the value against the known set before calling Parse.
- If the value comes from external input, validate it first or wrap Parse in a try/catch and fall back to a default trimming mode.
Example fix
// before
var trimming = TextTrimming.Parse("WordElipsis"); // typo, throws
// after
var trimming = TextTrimming.Parse("WordEllipsis"); Defensive patterns
Strategy: validation
Validate before calling
static readonly HashSet<string> s_knownTrimmings = new(StringComparer.OrdinalIgnoreCase)
{
"None", "CharacterEllipsis", "WordEllipsis", "PrefixCharacterEllipsis", "PathSegmentEllipsis"
};
static TextTrimming SafeParseTrimming(string s)
=> s != null && s_knownTrimmings.Contains(s.Trim())
? TextTrimming.Parse(s)
: TextTrimming.WordEllipsis; Try / catch
try { return TextTrimming.Parse(input); }
catch (FormatException) { return TextTrimming.WordEllipsis; } Prevention
- Validate trimming strings against the known enum names before parsing.
- Treat external/config values as untrusted and fall back to a default.
- Document supported trimming names wherever they are configured.
When it happens
Trigger: Calling TextTrimming.Parse with a string that is not one of the recognized enum names (case-insensitive match via the Matches helper). For example a typo like 'WordEllipsis ' with stray whitespace, or a value loaded from config/XAML that does not correspond to a TextTrimming mode.
Common situations: Deserializing a TextTrimming from user config, JSON, or a CSS-like string where the value is misspelled or uses a different casing not handled; version mismatches where an older codebase references a trimming name that was renamed or removed; copy-paste of WPF-only values that Avalonia does not support.
Related errors
- Invalid transform string: '{s}'.
- Too many provided values.
- Invalid value {value.Value} {unitString} for {function}
- Invalid format. {function} expects {count} value(s).
- Invalid unit: {part.ToString()}
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/97a76d82a64c1afd.
Report an issue: GitHub.