{"record":{"id":"5121133376ce6772","repo":"dotnet/wpf","slug":"cannot-convert-from-type","errorCode":null,"errorMessage":"Cannot convert from type.","messagePattern":"Cannot convert from type\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs","lineNumber":108,"sourceCode":"        /// <param name=\"value\">\n        /// The Object to convert.\n        /// </param>\n        /// <returns>\n        /// An Object that represents the converted value.\n        /// </returns>\n        public\n        override\n        object\n        ConvertFrom(\n            ITypeDescriptorContext              context,\n            System.Globalization.CultureInfo    culture,\n            object                              value\n            )\n        {\n            ArgumentNullException.ThrowIfNull(value);\n            if (!IsSupportedType(value.GetType()))\n            {\n                throw new NotSupportedException(SR.Converter_ConvertFromNotSupported);\n            }\n\n            throw new NotImplementedException();\n        }\n\n        /// <summary>\n        /// Converts the given value object to the specified type,\n        /// using the arguments.\n        /// </summary>\n        /// <param name=\"context\">\n        /// An ITypeDescriptorContext that provides a format context.\n        /// </param>\n        /// <param name=\"culture\">\n        /// A CultureInfo object. If null is passed, the current\n        /// culture is assumed.\n        /// </param>\n        /// <param name=\"value\">\n        /// The Object to convert.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs#L90-L126","documentation":"ColorTypeConverter.ConvertFrom only supports the source types it recognizes (via IsSupportedType). Passing a value whose type is not supported throws NotSupportedException with the message 'Cannot convert from type.' The converter is intentionally minimal for XPS serialization.","triggerScenarios":"Calling TypeConverter.ConvertFrom on ColorTypeConverter with a string or other type it does not list in IsSupportedType.","commonSituations":"Using ColorTypeConverter as a general-purpose Color parser in XAML or data binding; expecting ConvertFrom to parse hex color strings.","solutions":["Use ColorConverter (System.Windows.Media) instead of ColorTypeConverter to parse color strings.","Only pass types accepted by IsSupportedType to ConvertFrom.","Parse colors manually with ColorConverter.ConvertFromString.","Catch NotSupportedException and fall back to a real color parser."],"exampleFix":"// before\nvar color = (Color)new ColorTypeConverter().ConvertFromString(\"#FF0000\");\n// after\nvar color = (Color)ColorConverter.ConvertFromString(\"#FF0000\");","handlingStrategy":"try-catch","validationCode":"if (value == null || !value.GetType().IsInstanceOfType(typeof(Color))) // verify supported input before ConvertFrom\ncolorTypeConverter.ConvertFrom(null, null, value);","typeGuard":"static bool CanConvertFrom(object v) => v is Color;","tryCatchPattern":"try { return converter.ConvertFrom(context, culture, value); }\ncatch (NotSupportedException) { return ColorConverter.ConvertFromString(value.ToString()); }","preventionTips":["Use ColorConverter for string-based color parsing, not ColorTypeConverter.","Never treat ReachFramework serialization converters as general-purpose.","Check IsSupportedType behavior before calling ConvertFrom."],"tags":["wpf","type-converter","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"}