{"record":{"id":"ccb99969d275a092","repo":"dotnet/wpf","slug":"sr-converter-converttonotsupported-ccb999","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/PathFigureCollectionConverter.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 PathFigureCollection instance. </param>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType != null && value is PathFigureCollection)\n            {\n                PathFigureCollection instance = (PathFigureCollection)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/PathFigureCollectionConverter.cs#L119-L151","documentation":"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.","triggerScenarios":"Calling ConvertTo(instance, typeof(string)) on a PathFigureCollection whose CanSerializeToString() is false, typically with an empty collection or figures unsupported by the string format.","commonSituations":"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.","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."],"exampleFix":"// before\nvar s = (string)converter.ConvertTo(ctx, culture, figures, typeof(string));\n// after\nif (!figures.CanSerializeToString())\n{\n    throw new InvalidOperationException(\"This PathFigureCollection cannot be converted to a string\");\n}\nvar s = (string)converter.ConvertTo(ctx, culture, figures, typeof(string));","handlingStrategy":"validation","validationCode":"if (figures.CanSerializeToString())\n{\n    var s = (string)converter.ConvertTo(null, culture, figures, typeof(string));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    return (string)converter.ConvertTo(ctx, culture, figures, typeof(string));\n}\ncatch (NotSupportedException)\n{\n    return SerializeViaXaml(figures); // fallback serializer\n}","preventionTips":["Call CanSerializeToString() before attempting string conversion.","Avoid serializing empty or programmatically mutated PathFigureCollections to compact path strings."],"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"}