dotnet/wpf · error · ArgumentException
SR.Format(SR.General_BadType, "ConvertFrom")
Error message
SR.Format(SR.General_BadType, "ConvertFrom")
What it means
TextDecorationCollectionConverter.ConvertFrom throws an ArgumentException (SR.General_BadType for "ConvertFrom") when the input object is neither null nor a string. The converter only supports string input (or null, which produces a different GetConvertFromException).
Solutions
- Pass a string like "underline" or "strikethrough,overline" to the converter.
- If you already have a TextDecorationCollection, use it directly instead of converting.
- Use ConvertFromString rather than ConvertFrom for string sources.
Example fix
// before
converter.ConvertFrom(context, culture, new object[] { "underline" });
// after
converter.ConvertFrom(context, culture, "underline"); Defensive patterns
Strategy: type-guard
Validate before calling
if (input is not string s) throw new ArgumentException("TextDecorationCollectionConverter accepts only string input", nameof(input)); Type guard
bool IsConvertibleToString(object? v) => v is string;
Try / catch
try { result = converter.ConvertFrom(context, culture, input); } catch (ArgumentException) { /* handle non-string input */ } Prevention
- Only call the converter with string values
- Check input.GetType() before ConvertFrom
- Use ConvertFromString for string sources
When it happens
Trigger: Passing a non-string (e.g. an array, int, or TextDecorationCollection itself) to ConvertFrom / TypeDescriptor.ConvertFrom on TextDecorationCollectionConverter.
Common situations: XAML or designer value conversion pipelines feeding raw objects; reflection-based conversion helpers assuming broader input support.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- SR.Format(SR.MustBeOfType, nameof(value)…
- SR.General_Expected_Type
- SR.MustBeOfType
- SR.MustBeOfType: ' ' must be of type ' '. (args: value…
- SR.MustBeOfType: ' ' must be of type ' '. (args: value…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/58d4e38cfffcc1ca.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs:59
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
/// <summary>
/// Converts <paramref name="input"/> of <see langword="string"/> type to its <see cref="TextDecorationCollection"/> representation.
/// </summary>
/// <param name="context">Context information used for conversion, ignored currently.</param>
/// <param name="culture">The culture specifier to use, ignored currently.</param>
/// <param name="input">The string to convert from.</param>
/// <returns>A <see cref="TextDecorationCollection"/> representing the <see langword="string"/> specified by <paramref name="input"/>.</returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object input)
{
if (input is null)
throw GetConvertFromException(input);
if (input is not string value)
throw new ArgumentException(SR.Format(SR.General_BadType, "ConvertFrom"), nameof(input));
return ConvertFromString(value);
}
/// <summary>
/// Converts <paramref name="text"/> to its <see cref="TextDecorationCollection"/> representation.
/// </summary>
/// <param name="text">The string to be converted into TextDecorationCollection object.</param>
/// <returns>A <see cref="TextDecorationCollection"/> representing the <see cref="string"/> specified by <paramref name="text"/>.</returns>
/// <remarks>
/// The text parameter can be either be <see langword="null"/>; <see cref="string.Empty"/>; the string "None"
/// or a combination of the predefined <see cref="TextDecorations"/> names delimited by commas (,).
/// One or more blanks spaces can precede or follow each text decoration name or comma.
/// There can't be duplicate TextDecoration names in the string. The operation is case-insensitive.
/// </remarks>
public static new TextDecorationCollection ConvertFromString(string text)
{
if (text is null)View on GitHub (pinned to 81131a70a4)