dotnet/wpf · error · NotSupportedException
SR.Converter_ConvertToNotSupported
Error message
SR.Converter_ConvertToNotSupported
What it means
PathFigureCollectionConverter.ConvertTo throws NotSupportedException with SR.Converter_ConvertToNotSupported when the target PathFigureCollection cannot be serialized to a string (CanSerializeToString() returns false), e.g. it contains figures that do not round-trip to the compact path string syntax.
Solutions
- Check CanSerializeToString() before converting and fall back to another serialization (e.g. XAML/BAML) when false.
- Ensure the collection is non-empty and its figures are in a serializable state before converting.
- Catch NotSupportedException and serialize the object graph via a different mechanism.
Example fix
// before
var s = (string)converter.ConvertTo(ctx, culture, figures, typeof(string));
// after
if (!figures.CanSerializeToString())
{
throw new InvalidOperationException("This PathFigureCollection cannot be converted to a string");
}
var s = (string)converter.ConvertTo(ctx, culture, figures, typeof(string)); Defensive patterns
Strategy: validation
Validate before calling
if (figures.CanSerializeToString())
{
var s = (string)converter.ConvertTo(null, culture, figures, typeof(string));
} Try / catch
try
{
return (string)converter.ConvertTo(ctx, culture, figures, typeof(string));
}
catch (NotSupportedException)
{
return SerializeViaXaml(figures); // fallback serializer
} Prevention
- Call CanSerializeToString() before attempting string conversion.
- Avoid serializing empty or programmatically mutated PathFigureCollections to compact path strings.
When it happens
Trigger: Calling ConvertTo(instance, typeof(string)) on a PathFigureCollection whose CanSerializeToString() is false, typically with an empty collection or figures unsupported by the string format.
Common situations: Serializing a dynamically built or emptied PathFigureCollection; XAML serialization of Path figures that were constructed programmatically in a non-serializable state; round-tripping shapes between designer and code.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.Converter_ConvertToNotSupported
- Cannot convert from type.
- Cannot convert to type.
- Cannot convert to type.
- SR.Converter_ConvertToNotSupported
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ccb99969d275a092.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollectionConverter.cs:137
/// </exception>
/// <param name="context"> The ITypeDescriptorContext for this call. </param>
/// <param name="culture"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The object to convert to an instance of "destinationType". </param>
/// <param name="destinationType"> The type to which this will convert the PathFigureCollection instance. </param>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType != null && value is PathFigureCollection)
{
PathFigureCollection instance = (PathFigureCollection)value;
if (destinationType == typeof(string))
{
// When invoked by the serialization engine we can convert to string only for some instances
if (context != null && context.Instance != null)
{
if (!instance.CanSerializeToString())
{
throw new NotSupportedException(SR.Converter_ConvertToNotSupported);
}
}
// Delegate to the formatting/culture-aware ConvertToString method.
return instance.ConvertToString(null, culture);
}
}
// Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
View on GitHub (pinned to 81131a70a4)