{"record":{"id":"b60aacac55e52509","repo":"unoplatform/uno","slug":"conversion-from-type-0-is-not-supported","errorCode":null,"errorMessage":"Conversion from type {0} is not supported","messagePattern":"Conversion from type (.+?) is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeTypeConverter.cs","lineNumber":46,"sourceCode":"using Uno.Xaml;\n\nnamespace Uno.Xaml.Schema\n{\n\tpublic class XamlTypeTypeConverter : TypeConverter\n\t{\n\t\tpublic override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)\n\t\t{\n\t\t\treturn sourceType == typeof (string);\n\t\t}\n\n\t\tpublic override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)\n\t\t{\n\t\t\treturn destinationType == typeof (string);\n\t\t}\n\n\t\tpublic override Object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, Object value)\n\t\t{\n\t\t\tthrow new NotSupportedException (String.Format (CultureInfo.InvariantCulture, \"Conversion from type {0} is not supported\", value != null ? value.GetType () : null));\n\t\t}\n\n\t\tpublic override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n\t\t{\n\t\t\tif (!CanConvertTo (context, destinationType))\n\t\t\t\tthrow new NotSupportedException (String.Format (CultureInfo.InvariantCulture, \"Conversion to type {0} is not supported\", destinationType));\n\n\t\t\tvar vctx = (IValueSerializerContext) context;\n\t\t\tvar lookup = vctx != null ? (INamespacePrefixLookup) vctx.GetService (typeof (INamespacePrefixLookup)) : null;\n\t\t\tvar xt = value as XamlType;\n\t\t\tif (xt != null && destinationType == typeof (string)) {\n\t\t\t\tif (lookup != null)\n\t\t\t\t\treturn new XamlTypeName (xt).ToString (lookup);\n\t\t\t\telse\n\t\t\t\t\treturn xt.UnderlyingType != null ? xt.UnderlyingType.ToString () : xt.ToString ();\n\t\t\t}\n\t\t\telse\n\t\t\t\treturn base.ConvertTo (context, culture, value, destinationType); // it seems it still handles not-supported types (such as int).","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeTypeConverter.cs#L28-L64","documentation":"Thrown by XamlTypeTypeConverter.ConvertFrom — the type converter for XamlType always rejects ConvertFrom. It exists to support ConvertTo (XamlType → string) but does not implement any conversion path from arbitrary values (including strings) back to XamlType, so ConvertFrom unconditionally throws NotSupportedException.","triggerScenarios":"Calling ConvertFrom on a XamlTypeTypeConverter instance with any value type. This can happen via framework plumbing (XAML reader deserialization, TypeDescriptor.GetConverter(typeof(XamlType))) that tries round-trip conversion.","commonSituations":"A XAML reader or serializer infrastructure attempts bidirectional conversion on a XamlType-valued property and invokes ConvertFrom during deserialization. Misconfigured TypeConverter wiring where a custom adapter expects round-trippable converters.","solutions":["Do not call ConvertFrom on XamlTypeTypeConverter — it is intentionally unsupported. Use ConvertTo to go XamlType → string only.","If you need string → XamlType, resolve the type via XamlSchemaContext.GetXamlType(string) or XamlTypeName parsing instead.","Check CanConvertFrom before calling ConvertFrom — it returns false for all types except... actually it only returns true for typeof(string) but ConvertFrom still throws; treat XamlTypeTypeConverter as convert-to-only."],"exampleFix":"// before\nvar converter = new XamlTypeTypeConverter();\nvar xamlType = converter.ConvertFrom(context, culture, \"{ns}Name\");\n\n// after\nvar xamlType = schemaContext.GetXamlType(new XamlTypeName(\"ns\", \"Name\"));","handlingStrategy":"validation","validationCode":"var converter = new XamlTypeTypeConverter();\nif (converter.CanConvertFrom(context, value?.GetType() ?? typeof(object)))\n    result = converter.ConvertFrom(context, culture, value);\nelse\n    result = ResolveViaSchemaContext(value); // custom path","typeGuard":"static bool SupportsConvertFrom(XamlTypeTypeConverter c, Type t) => false; // never supported","tryCatchPattern":"try { converter.ConvertFrom(ctx, culture, val); }\ncatch (NotSupportedException) { /* use schema context resolution instead */ }","preventionTips":["Never call ConvertFrom on XamlTypeTypeConverter — it is unsupported by design.","Resolve XamlType via XamlSchemaContext.GetXamlType, not via type-converter round-trip."],"tags":["xaml","type-converter","not-supported","conversion","uno-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}