{"record":{"id":"e6a9f4fa48d92ec4","repo":"dotnet/wpf","slug":"sr-converter-converttonotsupported-transformconverter","errorCode":null,"errorMessage":"SR.Converter_ConvertToNotSupported","messagePattern":"SR\\.Converter_ConvertToNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformConverter.cs","lineNumber":137,"sourceCode":"        /// </exception>\n        /// <param name=\"context\"> The ITypeDescriptorContext for this call. </param>\n        /// <param name=\"culture\"> The CultureInfo which is respected when converting. </param>\n        /// <param name=\"value\"> The object to convert to an instance of \"destinationType\". </param>\n        /// <param name=\"destinationType\"> The type to which this will convert the Transform instance. </param>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType != null && value is Transform)\n            {\n                Transform instance = (Transform)value;\n\n                if (destinationType == typeof(string))\n                {\n                    // When invoked by the serialization engine we can convert to string only for some instances\n                    if (context != null && context.Instance != null)\n                    {\n                        if (!instance.CanSerializeToString())\n                        {\n                            throw new NotSupportedException(SR.Converter_ConvertToNotSupported);\n                        }\n                    }\n\n                    // Delegate to the formatting/culture-aware ConvertToString method.\n                    return instance.ConvertToString(null, culture);\n                }\n            }\n\n            // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)\n            return base.ConvertTo(context, culture, value, destinationType);\n        }\n    }\n}\n","sourceCodeStart":119,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformConverter.cs#L119-L151","documentation":"TransformConverter.ConvertTo can serialize only Transform instances whose CanSerializeToString() returns true (e.g., simple matrix/translate transforms). When the serialization engine requests a string conversion for an instance that has no string representation, the converter throws NotSupportedException(SR.Converter_ConvertToNotSupported) instead of producing a lossy or invalid string.","triggerScenarios":"Calling ConvertTo(context, culture, value, typeof(string)) — directly or via TypeDescriptor.GetConverter(...).ConvertToString — where the instance's CanSerializeToString() is false, such as complex transform instances the converter cannot represent as a string.","commonSituations":"Serializing a TransformGroup or animation-bearing transform to XAML/string form via the type converter; code generators or designers assuming every Freezable converts to string; storing transforms in string-based config formats.","solutions":["Convert only transforms that report CanSerializeToString() == true; check it before calling ConvertTo","Serialize the transform via XamlWriter or by decomposing it into a MatrixTransform (Matrix.Value) instead of the type converter","Round-trip complex transforms as a Matrix (matrix.ToString()) rather than relying on TransformConverter"],"exampleFix":"// before\nvar s = (string)converter.ConvertTo(ctx, culture, transform, typeof(string)); // throws for complex transforms\n// after\nvar s = transform.CanSerializeToString()\n    ? (string)converter.ConvertTo(ctx, culture, transform, typeof(string))\n    : transform.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);","handlingStrategy":"validation","validationCode":"if (!transform.CanSerializeToString())\n    throw new NotSupportedException($\"{transform.GetType().Name} has no string representation; use XAML or Matrix serialization.\");","typeGuard":"static bool IsStringSerializable(Transform t) => t != null && t.CanSerializeToString();","tryCatchPattern":"try { s = (string)converter.ConvertTo(ctx, culture, transform, typeof(string)); }\ncatch (NotSupportedException) { s = transform.Value.ToString(CultureInfo.InvariantCulture); }","preventionTips":["Check CanSerializeToString() before ConvertTo(string)","Prefer XamlWriter for complex transforms (groups, animations)","Round-trip via Matrix.ToString() with invariant culture when a string is mandatory"],"tags":["wpf","type-converter","serialization","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}