unoplatform/uno · error · NotSupportedException
Conversion from type {0} is not supported
Error message
Conversion from type {0} is not supported What it means
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.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeTypeConverter.cs:46
using Uno.Xaml;
namespace Uno.Xaml.Schema
{
public class XamlTypeTypeConverter : TypeConverter
{
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof (string);
}
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof (string);
}
public override Object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, Object value)
{
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Conversion from type {0} is not supported", value != null ? value.GetType () : null));
}
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (!CanConvertTo (context, destinationType))
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Conversion to type {0} is not supported", destinationType));
var vctx = (IValueSerializerContext) context;
var lookup = vctx != null ? (INamespacePrefixLookup) vctx.GetService (typeof (INamespacePrefixLookup)) : null;
var xt = value as XamlType;
if (xt != null && destinationType == typeof (string)) {
if (lookup != null)
return new XamlTypeName (xt).ToString (lookup);
else
return xt.UnderlyingType != null ? xt.UnderlyingType.ToString () : xt.ToString ();
}
else
return base.ConvertTo (context, culture, value, destinationType); // it seems it still handles not-supported types (such as int).View on GitHub (pinned to 0418340488)
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.
Example fix
// before
var converter = new XamlTypeTypeConverter();
var xamlType = converter.ConvertFrom(context, culture, "{ns}Name");
// after
var xamlType = schemaContext.GetXamlType(new XamlTypeName("ns", "Name")); Defensive patterns
Strategy: validation
Validate before calling
var converter = new XamlTypeTypeConverter();
if (converter.CanConvertFrom(context, value?.GetType() ?? typeof(object)))
result = converter.ConvertFrom(context, culture, value);
else
result = ResolveViaSchemaContext(value); // custom path Type guard
static bool SupportsConvertFrom(XamlTypeTypeConverter c, Type t) => false; // never supported
Try / catch
try { converter.ConvertFrom(ctx, culture, val); }
catch (NotSupportedException) { /* use schema context resolution instead */ } Prevention
- Never call ConvertFrom on XamlTypeTypeConverter — it is unsupported by design.
- Resolve XamlType via XamlSchemaContext.GetXamlType, not via type-converter round-trip.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Conversion to type {0} is not supported
- Cannot cast object '{0}' to string
- instance type '{0}' has no default constructor.
- context
- Value must be non-null string.
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/b60aacac55e52509.
Report an issue: GitHub.