{"record":{"id":"201f549db6f50743","repo":"AvaloniaUI/Avalonia","slug":"could-not-parse-text-decoration","errorCode":null,"errorMessage":"Could not parse text decoration.","messagePattern":"Could not parse text decoration\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/TextDecorationCollection.cs","lineNumber":69,"sourceCode":"                textDecorations.Add(new TextDecoration { Location = textDecorationLocation });\n            }\n\n            return textDecorations;\n        }\n\n        /// <summary>\n        /// Parses a <see cref=\"TextDecorationLocation\"/> string.\n        /// </summary>\n        /// <param name=\"s\">The string.</param>\n        /// <returns>The <see cref=\"TextDecorationLocation\"/>.</returns>\n        private static TextDecorationLocation GetTextDecorationLocation(ReadOnlySpan<char> s)\n        {\n            if (SpanHelpers.TryParseEnum<TextDecorationLocation>(s,true, out var location))\n            {\n                return location;\n            }\n\n            throw new ArgumentException(\"Could not parse text decoration.\", nameof(s));\n        }\n    }\n}\n","sourceCodeStart":51,"sourceCodeEnd":73,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/TextDecorationCollection.cs#L51-L73","documentation":"Thrown by GetTextDecorationLocation when SpanHelpers.TryParseEnum<TextDecorationLocation> fails for a token. The token must match a TextDecorationLocation enum name (case-insensitive, e.g. Baseline, OverLine, Strikethrough, Underline). Any unrecognized word, abbreviation, or stray character fails the parse.","triggerScenarios":"Strings like 'underline2', 'italic' (not a decoration), 'line-through' (the CSS name, not the enum name), or a typo like 'Underlin'.","commonSituations":"Mapping CSS text-decoration values directly (CSS uses 'line-through' where Avalonia uses 'Strikethrough'); user-typed decoration names; abbreviations or localized names.","solutions":["Use the exact TextDecorationLocation enum names: Baseline, OverLine, Strikethrough, Underline (case-insensitive).","Map CSS names before parsing: 'line-through' -> 'Strikethrough', 'overline' -> 'OverLine'.","Trim whitespace and validate each token against Enum.GetNames<TextDecorationLocation>() before composing the string."],"exampleFix":"// before\nvar d = TextDecorationCollection.Parse(\"line-through,underline\");\n\n// after\nvar d = TextDecorationCollection.Parse(\"Strikethrough,Underline\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> Valid =\n    new(Enum.GetNames<TextDecorationLocation>(), StringComparer.OrdinalIgnoreCase);\nstatic bool IsValidDecoration(string tok) => Valid.Contains(tok.Trim());","typeGuard":"static bool IsValidDecorationName(string s) =>\n    Enum.GetNames<TextDecorationLocation>().Any(n =>\n        n.Equals(s, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { var d = TextDecorationCollection.Parse(s); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Could not parse\"))\n{ /* map CSS names or report invalid token */ }","preventionTips":["Use exact TextDecorationLocation enum names (Baseline, OverLine, Strikethrough, Underline).","Map CSS values ('line-through' -> 'Strikethrough') before parsing.","Validate each token against the enum names when data is user-supplied."],"tags":["avalonia","text","text-decoration","parse","enum"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}