{"record":{"id":"9c7966d6013c0b8b","repo":"dotnet/wpf","slug":"sr-general-expected-type","errorCode":null,"errorMessage":"SR.General_Expected_Type","messagePattern":"SR\\.General_Expected_Type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollectionConverter.cs","lineNumber":67,"sourceCode":"\n        /// <summary>\n        /// Returns true if this type converter can convert to the given type.\n        /// </summary>\n        /// <returns>\n        /// bool - True if this converter can convert to the provided type, false if not.\n        /// </returns>\n        /// <param name=\"context\"> The ITypeDescriptorContext for this call. </param>\n        /// <param name=\"destinationType\"> The Type being queried for support. </param>\n        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)\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 (!(context.Instance is PathFigureCollection))\n                    {\n                        throw new ArgumentException(SR.Format(SR.General_Expected_Type, \"PathFigureCollection\"), nameof(context));\n                    }\n\n                    PathFigureCollection value = (PathFigureCollection)context.Instance;\n\n                    return value.CanSerializeToString();\n                }\n\n                return true;\n            }\n\n            return base.CanConvertTo(context, destinationType);\n        }\n\n        /// <summary>\n        /// Attempts to convert to a PathFigureCollection from the given object.\n        /// </summary>\n        /// <returns>\n        /// The PathFigureCollection which was constructed.","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollectionConverter.cs#L49-L85","documentation":"PathFigureCollectionConverter.CanConvertTo throws ArgumentException with SR.General_Expected_Type when the serialization context supplies an Instance that is not a PathFigureCollection. The converter only supports converting to string for actual PathFigureCollection instances.","triggerScenarios":"Calling CanConvertTo(context, typeof(string)) with an ITypeDescriptorContext whose Instance property holds an object of a different type.","commonSituations":"Reusing the converter manually with a mismatched context instance; designer/serialization pipelines passing the wrong object as context.Instance; custom TypeDescriptor setups wiring this converter to another type.","solutions":["Pass a context whose Instance is a PathFigureCollection.","Check context.Instance is PathFigureCollection before invoking the converter and return false otherwise.","Use the correct TypeConverter for the object type being serialized."],"exampleFix":"// before\nbool ok = converter.CanConvertTo(context, typeof(string)); // context.Instance is not a PathFigureCollection\n// after\nbool ok = context?.Instance is PathFigureCollection && converter.CanConvertTo(context, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (context?.Instance is PathFigureCollection)\n    return converter.CanConvertTo(context, destinationType);\nreturn false;","typeGuard":"context?.Instance is PathFigureCollection collection","tryCatchPattern":"try\n{\n    return converter.CanConvertTo(context, typeof(string));\n}\ncatch (ArgumentException)\n{\n    return false; // context.Instance was not a PathFigureCollection\n}","preventionTips":["Only pass type-descriptor contexts whose Instance matches the converter's target type.","Use TypeDescriptor.GetConverter(instance) to obtain the correct converter automatically."],"tags":["wpf","type-converter","type-mismatch"],"backgroundTag":"type-mismatch","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"}