dotnet/wpf · error · ArgumentException

SR.Format(SR.InvalidTextDecorationCollectionString, text)

Error message

SR.Format(SR.InvalidTextDecorationCollectionString, text)

What it means

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.

Solutions

  1. Use only supported keywords: none, underline, overline, strikethrough, baseline (comma-separated).
  2. Fix spelling/casing of the decoration string.
  3. Build the collection programmatically with new TextDecorationCollection(TextDecorations.Underline) instead of parsing strings.

Example fix

// before
var td = (TextDecorationCollection)converter.ConvertFromString("underlined");
// after
var td = (TextDecorationCollection)converter.ConvertFromString("underline");
Defensive patterns

Strategy: validation

Validate before calling

static readonly string[] Valid = { "none", "underline", "overline", "strikethrough", "baseline" };
bool IsValidDecorationString(string s) => s.Split(',').Select(t => t.Trim().ToLowerInvariant()).All(Valid.Contains);

Try / catch

try { td = TextDecorationCollectionConverter.ConvertFromString(text); } catch (ArgumentException) { td = new TextDecorationCollection(); }

Prevention

When it happens

Trigger: Calling ConvertFromString with an unrecognized token, e.g. "bold" or misspelled "underlined"; XAML attribute TextDecorations="blink".

Common situations: Hand-written XAML with invalid decoration names; parsing user input as decoration strings; casing/typo mistakes in config-driven styling.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/e9f528c5e3064d13. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs:118

                }
                else if (decoration.Equals("Baseline", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.BaselineMatch))
                {
                    textDecorations.Add(TextDecorations.Baseline[0]);
                    matchedDecorations |= Decorations.BaselineMatch;
                }
                else if (decoration.Equals("Underline", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.UnderlineMatch))
                {
                    textDecorations.Add(TextDecorations.Underline[0]);
                    matchedDecorations |= Decorations.UnderlineMatch;
                }
                else if (decoration.Equals("Strikethrough", StringComparison.OrdinalIgnoreCase) && !matchedDecorations.HasFlag(Decorations.StrikethroughMatch))
                {
                    textDecorations.Add(TextDecorations.Strikethrough[0]);
                    matchedDecorations |= Decorations.StrikethroughMatch;
                }
                else
                {
                    throw new ArgumentException(SR.Format(SR.InvalidTextDecorationCollectionString, text));
                }
            }

            return textDecorations;
        }

        /// <summary>
        /// Converts a <paramref name="value"/> of <see cref="TextDecorationCollection"/> to the specified <paramref name="destinationType"/>.
        /// </summary>
        /// <param name="context">Context information used for conversion.</param>
        /// <param name="culture">The culture specifier to use.</param>
        /// <param name="value">Duration value to convert from.</param>
        /// <param name="destinationType">Type being evaluated for conversion.</param>
        /// <returns><see langword="null"/> will always be returned because <see cref="TextDecorations"/> cannot be converted to any other type.</returns>        
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(InstanceDescriptor) && value is IEnumerable<TextDecoration>)
            {

View on GitHub (pinned to 81131a70a4)