dotnet/wpf · error · NotSupportedException
SR.Converter_ConvertToNotSupported
Error message
SR.Converter_ConvertToNotSupported
What it means
This SR resource string backs a NotSupportedException thrown by generated TypeConverter ConvertTo code for animatable WPF resource types (mcg generator, ManagedResource.cs). Animatable resources must be frozen before conversion; the generated converter refuses to convert instances whose CanFreeze is true but are not frozen. It signals that the requested type conversion is not supported for this resource instance in its current state.
Solutions
- Freeze the resource (or make it immutable) before invoking the converter, so CanFreeze is false
- Verify the resource type actually supports ConvertTo conversion; use a converter intended for the target type
- If you own the mcg resource definition, mark the resource as not animatable or provide a custom TypeConverter
- Catch NotSupportedException and fall back to manual serialization of the resource
Example fix
// before object v = converter.ConvertTo(resource, typeof(string)); // throws if unfrozen // after if (resource.CanFreeze) resource.Freeze(); object v = converter.ConvertTo(resource, typeof(string));
Defensive patterns
Strategy: validation
Validate before calling
if (resource.CanFreeze) resource.Freeze(); // ConvertTo is now safe for animatable resources
Try / catch
try { return converter.ConvertTo(value, targetType); }
catch (NotSupportedException) { return manualSerialize(value); } Prevention
- Freeze animatable resources as soon as they are configured
- Never pass live, still-mutable Freezables into converters
When it happens
Trigger: Calling TypeConverter.ConvertTo on a generated wrapper for an animatable resource (resource.IsAnimatable) when the instance reports CanFreeze == true (i.e. it is still freezable/unfrozen and therefore mutable).
Common situations: Using the design-time or serialization converter on an unfrozen Animatable-derived resource (e.g. a Brush or DoubleAnimation wrapper) during XAML serialization or tooling; passing a freshly created, never-frozen instance to a converter.
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.
- Converter_ConvertToNotSupported
- General_Expected_Type (ImageSource)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d7b07f117a43dc77.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/ManagedResource.cs:2771
if (resource.IsAbstract)
{
return
[[inline]]internal abstract InstanceDescriptor ToInstanceDescriptor();[[/inline]];
}
if (resource.IsCollection)
{
StringCodeSink notSupportedCheck = new StringCodeSink();
string modifiers = "";
if (resource.IsAnimatable)
{
notSupportedCheck.Write(
[[inline]]
if (!CanFreeze)
{
throw new NotSupportedException(SR.Converter_ConvertToNotSupported);
}
[[/inline]]
);
}
if (resource.Extends != null)
{
modifiers = "override";
}
// Override if derived from parent class. If abstract provide abstract implementation.
return
[[inline]]
internal [[modifiers]] InstanceDescriptor ToInstanceDescriptor()
{
[[notSupportedCheck]]
View on GitHub (pinned to 81131a70a4)