{"record":{"id":"e9f528c5e3064d13","repo":"dotnet/wpf","slug":"sr-format-sr-invalidtextdecorationcollectionstring-text","errorCode":null,"errorMessage":"SR.Format(SR.InvalidTextDecorationCollectionString, text)","messagePattern":"SR\\.Format\\(SR\\.InvalidTextDecorationCollectionString, text\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs","lineNumber":118,"sourceCode":"                }\n                else if (decoration.Equals(\"Baseline\", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.BaselineMatch))\n                {\n                    textDecorations.Add(TextDecorations.Baseline[0]);\n                    matchedDecorations |= Decorations.BaselineMatch;\n                }\n                else if (decoration.Equals(\"Underline\", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.UnderlineMatch))\n                {\n                    textDecorations.Add(TextDecorations.Underline[0]);\n                    matchedDecorations |= Decorations.UnderlineMatch;\n                }\n                else if (decoration.Equals(\"Strikethrough\", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.StrikethroughMatch))\n                {\n                    textDecorations.Add(TextDecorations.Strikethrough[0]);\n                    matchedDecorations |= Decorations.StrikethroughMatch;\n                }\n                else\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidTextDecorationCollectionString, text));\n                }\n            }\n\n            return textDecorations;\n        }\n\n        /// <summary>\n        /// Converts a <paramref name=\"value\"/> of <see cref=\"TextDecorationCollection\"/> to the specified <paramref name=\"destinationType\"/>.\n        /// </summary>\n        /// <param name=\"context\">Context information used for conversion.</param>\n        /// <param name=\"culture\">The culture specifier to use.</param>\n        /// <param name=\"value\">Duration value to convert from.</param>\n        /// <param name=\"destinationType\">Type being evaluated for conversion.</param>\n        /// <returns><see langword=\"null\"/> will always be returned because <see cref=\"TextDecorations\"/> cannot be converted to any other type.</returns>        \n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType == typeof(InstanceDescriptor) && value is IEnumerable<TextDecoration>)\n            {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs#L100-L136","documentation":"TextDecorationCollectionConverter.ConvertFromString throws an ArgumentException with SR.InvalidTextDecorationCollectionString when the input string contains tokens it cannot map to known text decorations. Only specific keywords (none, underline, strikethrough, overline, baseline and combinations) are accepted.","triggerScenarios":"Calling ConvertFromString with an unrecognized token, e.g. \"bold\" or misspelled \"underlined\"; XAML attribute TextDecorations=\"blink\".","commonSituations":"Hand-written XAML with invalid decoration names; parsing user input as decoration strings; casing/typo mistakes in config-driven styling.","solutions":["Use only supported keywords: none, underline, overline, strikethrough, baseline (comma-separated).","Fix spelling/casing of the decoration string.","Build the collection programmatically with new TextDecorationCollection(TextDecorations.Underline) instead of parsing strings."],"exampleFix":"// before\nvar td = (TextDecorationCollection)converter.ConvertFromString(\"underlined\");\n// after\nvar td = (TextDecorationCollection)converter.ConvertFromString(\"underline\");","handlingStrategy":"validation","validationCode":"static readonly string[] Valid = { \"none\", \"underline\", \"overline\", \"strikethrough\", \"baseline\" };\nbool IsValidDecorationString(string s) => s.Split(',').Select(t => t.Trim().ToLowerInvariant()).All(Valid.Contains);","typeGuard":null,"tryCatchPattern":"try { td = TextDecorationCollectionConverter.ConvertFromString(text); } catch (ArgumentException) { td = new TextDecorationCollection(); }","preventionTips":["Whitelist decoration keywords before parsing","Normalize casing and trim tokens","Prefer building collections programmatically over string parsing"],"tags":["wpf","type-converter","invalid-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}