{"record":{"id":"d6e0e438799c1006","repo":"unoplatform/uno","slug":"conversion-to-type-0-is-not-supported","errorCode":null,"errorMessage":"Conversion to type {0} is not supported","messagePattern":"Conversion to type (.+?) is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeTypeConverter.cs","lineNumber":52,"sourceCode":"\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).\n\t\t}\n\t}\n}\n","sourceCodeStart":34,"sourceCodeEnd":68,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeTypeConverter.cs#L34-L68","documentation":"Thrown by XamlTypeTypeConverter.ConvertTo when CanConvertTo returns false for the requested destinationType. The converter only supports converting XamlType to typeof(string); any other destination type (or a non-XamlType source value that falls through to base.ConvertTo) triggers NotSupportedException.","triggerScenarios":"Calling ConvertTo(context, culture, value, typeof(int)) or any destinationType other than string. Or calling ConvertTo with a value that is not a XamlType and a destinationType that base.ConvertTo also cannot handle.","commonSituations":"Generic XAML serialization pipeline that enumerates target types. Misconfigured binding or markup-extension code that requests conversion to an incompatible type. Code that assumes a TypeConverter can round-trip to any Type.","solutions":["Only request conversion to typeof(string) from XamlTypeTypeConverter.","Check CanConvertTo(context, destinationType) before calling ConvertTo and handle false gracefully.","If the value is not a XamlType, use a TypeConverter appropriate to the value's actual type."],"exampleFix":"// before\nstring name = (string)converter.ConvertTo(ctx, culture, xamlType, typeof(string)); // OK\nint bad = (int)converter.ConvertTo(ctx, culture, xamlType, typeof(int)); // throws\n\n// after\nif (converter.CanConvertTo(ctx, typeof(string)))\n    name = (string)converter.ConvertTo(ctx, culture, xamlType, typeof(string));","handlingStrategy":"validation","validationCode":"if (converter.CanConvertTo(context, destinationType))\n    return converter.ConvertTo(context, culture, value, destinationType);","typeGuard":"static bool CanConvert(XamlTypeTypeConverter c, ITypeDescriptorContext ctx, Type dest)\n    => c.CanConvertTo(ctx, dest);","tryCatchPattern":"try { return converter.ConvertTo(ctx, culture, value, destType); }\ncatch (NotSupportedException) { /* handle unsupported target type */ }","preventionTips":["Always check CanConvertTo before ConvertTo.","XamlTypeTypeConverter only supports string as a destination type."],"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"}