dotnet/wpf · error · NotSupportedException

Cannot convert from type.

Error message

Cannot convert from type.

What it means

FontTypeConverter.ConvertFrom rejects null (ArgumentNullException), unsupported value types (NotSupportedException 'Cannot convert from type.'), and finally throws NotImplementedException for supported types - conversion 'from' is deliberately not implemented for font serialization.

Solutions

  1. Do not use FontTypeConverter to build FontFamily/GlyphRun objects; construct them directly.
  2. Ensure only the converter's supported value types are passed.
  3. Catch NotSupportedException/NotImplementedException at the converter boundary.
  4. Register a custom converter implementing ConvertFrom if needed.

Example fix

// before
var font = converter.ConvertFrom(context, culture, fontFamilyString);
// after
var font = new FontFamily(fontFamilyString);
Defensive patterns

Strategy: type-guard

Validate before calling

if (value == null) throw new ArgumentNullException(nameof(value));
if (value is not Color) throw new NotSupportedException("unsupported source type");

Type guard

static bool CanConvertFrom(object v) => v != null; // ConvertFrom still throws NotImplementedException

Try / catch

try { return converter.ConvertFrom(context, culture, value); }
catch (Exception ex) when (ex is ArgumentNullException or NotSupportedException or NotImplementedException) { /* fallback construction */ }

Prevention

When it happens

Trigger: Calling ConvertFrom on FontTypeConverter: null value, a value whose type fails IsSupportedType (e.g. a Color), or any supported-typed value (always throws).

Common situations: Tests and serialization pipelines probing the converter; XAML systems expecting standard TypeConverter behavior for fonts.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/FontTypeConverter.cs:106

        /// <param name="value">
        /// The Object to convert.
        /// </param>
        /// <returns>
        /// An Object that represents the converted value.
        /// </returns>
        public
        override
        object
        ConvertFrom(
            ITypeDescriptorContext              context,
            System.Globalization.CultureInfo    culture,
            object                              value
            )
        {
            ArgumentNullException.ThrowIfNull(value);
            if (!IsSupportedType(value.GetType()))
            {
                throw new NotSupportedException(SR.Converter_ConvertFromNotSupported);
            }

            throw new NotImplementedException();
        }

        /// <summary>
        /// Converts the given value object to the specified type,
        /// using the arguments.
        /// </summary>
        /// <param name="context">
        /// An ITypeDescriptorContext that provides a format context.
        /// </param>
        /// <param name="culture">
        /// A CultureInfo object. If null is passed, the current
        /// culture is assumed.
        /// </param>
        /// <param name="value">
        /// The Object to convert.

View on GitHub (pinned to 81131a70a4)