dotnet/wpf · error · ArgumentException

SR.Format(SR.General_BadType, "ConvertFrom")

Error message

SR.Format(SR.General_BadType, "ConvertFrom")

What it means

This TypeConverter's ConvertFrom accepts only string input. If value is not a string (e.g. an arbitrary object or null), an ArgumentException with SR.General_BadType formatted with 'ConvertFrom' is thrown, with 'value' as the parameter name.

Solutions

  1. Pass a string to ConvertFrom, or call ConvertToString/ToString first
  2. Use ConvertFromInvariantString with a culture-independent string when parsing serialized values
  3. Check value is a string (or use TypeDescriptor) before calling

Example fix

// before
var result = converter.ConvertFrom(context, culture, someObject);
// after
var result = converter.ConvertFrom(context, culture, someObject?.ToString() ?? string.Empty);
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is not string s) {
    // convert or reject before calling ConvertFrom
    value = value?.ToString();
}

Type guard

static bool IsConvertibleString(object? value) => value is string s && s.Length > 0;

// usage: if (IsConvertibleString(input)) converter.ConvertFrom(ctx, culture, input);

Try / catch

try {
    result = converter.ConvertFrom(context, culture, value);
} catch (ArgumentException ex) when (ex.ParamName == "value") {
    // handle non-string input
}

Prevention

When it happens

Trigger: Calling converter.ConvertFrom(context, culture, value) with value that is not a string — e.g. passing a non-string object from XAML or binding code, or passing null.

Common situations: Custom converters used in XAML parsing with untyped markup extensions, or code feeding raw objects into type converters expecting pre-converted strings.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IListConverters.cs:55

        {
            return destinationType == typeof(string); // can only convert to string
        }

        /// <Summary>
        /// Converts from a string.
        /// </Summary>
        public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, object value)
        {
            if (null == value)
            {
                throw GetConvertFromException(value);
            }

            string s = value as string;

            if (null == s)
            {
                throw new ArgumentException(SR.Format(SR.General_BadType, "ConvertFrom"), nameof(value));
            }

            return ConvertFromCore(td, ci, s);            
        }

        /// <Summary>
        /// Converts to a string
        /// </Summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != null)
                return ConvertToCore(context, culture, value, destinationType);

            // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
            return base.ConvertTo(context, culture, value, destinationType);
        }
        
        /// <summary>

View on GitHub (pinned to 81131a70a4)