{"record":{"id":"d7b07f117a43dc77","repo":"dotnet/wpf","slug":"sr-converter-converttonotsupported-managedresource","errorCode":null,"errorMessage":"SR.Converter_ConvertToNotSupported","messagePattern":"SR\\.Converter_ConvertToNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/ManagedResource.cs","lineNumber":2771,"sourceCode":"\n            if (resource.IsAbstract)\n            {\n                return\n                    [[inline]]internal abstract InstanceDescriptor ToInstanceDescriptor();[[/inline]];\n            }\n\n            if (resource.IsCollection)\n            {\n                StringCodeSink notSupportedCheck = new StringCodeSink();\n                string modifiers = \"\";\n\n                if (resource.IsAnimatable)\n                {\n                    notSupportedCheck.Write(\n                        [[inline]]\n                            if (!CanFreeze)\n                            {\n                                throw new NotSupportedException(SR.Converter_ConvertToNotSupported);\n                            }\n                        [[/inline]]\n                    );\n                }\n\n                if (resource.Extends != null)\n                {\n                    modifiers = \"override\";\n                }\n\n                // Override if derived from parent class.  If abstract provide abstract implementation.\n\n                return\n                    [[inline]]\n                        internal [[modifiers]] InstanceDescriptor ToInstanceDescriptor()\n                        {\n                            [[notSupportedCheck]]\n","sourceCodeStart":2753,"sourceCodeEnd":2789,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/ManagedResource.cs#L2753-L2789","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nobject v = converter.ConvertTo(resource, typeof(string)); // throws if unfrozen\n// after\nif (resource.CanFreeze) resource.Freeze();\nobject v = converter.ConvertTo(resource, typeof(string));","handlingStrategy":"validation","validationCode":"if (resource.CanFreeze) resource.Freeze();\n// ConvertTo is now safe for animatable resources","typeGuard":null,"tryCatchPattern":"try { return converter.ConvertTo(value, targetType); }\ncatch (NotSupportedException) { return manualSerialize(value); }","preventionTips":["Freeze animatable resources as soon as they are configured","Never pass live, still-mutable Freezables into converters"],"tags":["wpf","typeconverter","notsupported","freezable"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}