dotnet/wpf · error · NotSupportedException
SR.Converter_ConvertFromNotSupported
Error message
SR.Converter_ConvertFromNotSupported
What it means
KeySplineConverter.ConvertFrom throws NotSupportedException (SR.Converter_ConvertFromNotSupported) when the value argument is null, because the type converter only supports converting string (and KeySpline) input to a KeySpline. Converting from null is explicitly unsupported rather than treated as an empty spline.
Solutions
- Check for null before calling ConvertFrom and substitute a default KeySpline (e.g. new KeySpline(0,0,1,1)).
- In XAML, supply a non-null value or a default in markup rather than relying on the converter.
- Use ConvertFromString only for genuine strings; handle null at the caller level.
- Catch NotSupportedException and fall back to a default spline if null input is expected in your pipeline.
Example fix
// before
var spline = (KeySpline)converter.ConvertFrom(context, culture, possiblyNull);
// after
var spline = possiblyNull == null
? new KeySpline(new Point(0, 0), new Point(1, 1))
: (KeySpline)converter.ConvertFrom(context, culture, possiblyNull); Defensive patterns
Strategy: type-guard
Validate before calling
if (value == null)
return new KeySpline(new Point(0, 0), new Point(1, 1)); // default spline
var spline = (KeySpline)converter.ConvertFrom(context, culture, value); Type guard
static bool IsConvertibleValue(object v) => v is string or KeySpline;
Try / catch
try
{
spline = (KeySpline)converter.ConvertFrom(context, culture, value);
}
catch (NotSupportedException)
{
spline = new KeySpline(new Point(0, 0), new Point(1, 1));
} Prevention
- Null-check converter input before calling ConvertFrom
- Coerce nulls to default values at the deserialization layer, not in the converter
- In XAML, provide explicit default markup instead of relying on null conversion
- Restrict converter calls to string/KeySpline inputs via a wrapper API
When it happens
Trigger: TypeDescriptor/Convert.ChangeType style pipelines calling converter.ConvertFrom(context, culture, null), e.g. during XAML or data-binding value conversion when the source value is null.
Common situations: XAML attribute bound to a null resource; deserializers invoking type converters for missing fields; code calling KeySplineConverter directly with a null input while assuming default-value semantics.
Related errors
- ArgumentNullException (nameof(targetObject))
- Buffer address passed to GetText cannot be NULL.
- Cannot convert from type.
- Cannot convert from type.
- Cannot convert to type.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/88272a76a20a945b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySplineConverter.cs:67
else
{
return false;
}
}
/// <summary>
/// ConvertFrom
/// </summary>
public override object ConvertFrom(
ITypeDescriptorContext context,
CultureInfo cultureInfo,
object value)
{
string stringValue = value as string;
if (value == null)
{
throw new NotSupportedException(SR.Converter_ConvertFromNotSupported);
}
TokenizerHelper th = new TokenizerHelper(stringValue, cultureInfo);
return new KeySpline(
Convert.ToDouble(th.NextTokenRequired(), cultureInfo),
Convert.ToDouble(th.NextTokenRequired(), cultureInfo),
Convert.ToDouble(th.NextTokenRequired(), cultureInfo),
Convert.ToDouble(th.NextTokenRequired(), cultureInfo));
}
/// <summary>
/// TypeConverter method implementation.
/// </summary>
/// <param name="context">ITypeDescriptorContext</param>
/// <param name="cultureInfo">current culture (see CLR specs), null is a valid value</param>
/// <param name="value">value to convert from</param>
/// <param name="destinationType">Type to convert to</param>View on GitHub (pinned to 81131a70a4)