{"record":{"id":"97a76d82a64c1afd","repo":"AvaloniaUI/Avalonia","slug":"invalid-text-trimming-string-s","errorCode":null,"errorMessage":"Invalid text trimming string: '{s}'.","messagePattern":"Invalid text trimming string: '(.+?)'\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/TextTrimming.cs","lineNumber":85,"sourceCode":"            }\n            if (Matches(nameof(CharacterEllipsis)))\n            {\n                return CharacterEllipsis;\n            }\n            else if (Matches(nameof(WordEllipsis)))\n            {\n                return WordEllipsis;\n            }\n            else if (Matches(nameof(PrefixCharacterEllipsis)))\n            {\n                return PrefixCharacterEllipsis;\n            }\n            else if (Matches(nameof(PathSegmentEllipsis)))\n            {\n                return PathSegmentEllipsis;\n            }\n\n            throw new FormatException($\"Invalid text trimming string: '{s}'.\");\n        }\n    }\n}\n","sourceCodeStart":67,"sourceCodeEnd":89,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/TextTrimming.cs#L67-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar trimming = TextTrimming.Parse(\"WordElipsis\"); // typo, throws\n\n// after\nvar trimming = TextTrimming.Parse(\"WordEllipsis\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> s_knownTrimmings = new(StringComparer.OrdinalIgnoreCase)\n{\n    \"None\", \"CharacterEllipsis\", \"WordEllipsis\", \"PrefixCharacterEllipsis\", \"PathSegmentEllipsis\"\n};\n\nstatic TextTrimming SafeParseTrimming(string s)\n    => s != null && s_knownTrimmings.Contains(s.Trim())\n        ? TextTrimming.Parse(s)\n        : TextTrimming.WordEllipsis;","typeGuard":null,"tryCatchPattern":"try { return TextTrimming.Parse(input); }\ncatch (FormatException) { return TextTrimming.WordEllipsis; }","preventionTips":["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."],"tags":["text-trimming","parse","format-exception","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}