unoplatform/uno · error · XamlSchemaException
ConverterType '{0}' is not derived from '{1}' type
Error message
ConverterType '{0}' is not derived from '{1}' type What it means
Thrown by XamlValueConverter<TConverterBase>.CreateInstance (accessed via the ConverterInstance property) when the ConverterType is not assignable to the generic TConverterBase constraint. CreateInstance instantiates the converter, and the assignability check guards against a type mismatch that would otherwise cause an InvalidCastException during Activator.CreateInstance.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlValueConverter.cs:96
public bool Equals (XamlValueConverter<TConverterBase> other)
{
return !IsNull (other) && ConverterType == other.ConverterType && TargetType == other.TargetType && Name == other.Name;
}
public override bool Equals (object obj)
{
var a = obj as XamlValueConverter<TConverterBase>;
return Equals (a);
}
protected virtual TConverterBase CreateInstance ()
{
if (ConverterType == null)
return null;
if (!typeof (TConverterBase).IsAssignableFrom (ConverterType))
throw new XamlSchemaException (String.Format (CultureInfo.InvariantCulture, "ConverterType '{0}' is not derived from '{1}' type", ConverterType, typeof (TConverterBase)));
if (TargetType != null && TargetType.UnderlyingType != null) {
// special case: Enum
if (TargetType.UnderlyingType.IsEnum)
return (TConverterBase) (object) new EnumConverter (TargetType.UnderlyingType);
// special case: Nullable<T>
if (TargetType.IsNullable && TargetType.UnderlyingType.IsValueType)
return (TConverterBase) (object) new NullableConverter (TargetType.UnderlyingType);
}
if (ConverterType.GetConstructor (Type.EmptyTypes) == null)
return null;
return (TConverterBase) Activator.CreateInstance (ConverterType, true);
}
public override int GetHashCode ()
{View on GitHub (pinned to 0418340488)
Solutions
- Verify the converterType passed to XamlValueConverter<T> actually derives from (or implements) TConverterBase before construction.
- In custom XamlSchemaContext overrides, ensure GetXamlValueConverter returns converters whose Type matches the requested generic kind (TypeConverter vs ValueSerializer).
- Add a type guard: typeof(TConverterBase).IsAssignableFrom(converterType) before creating the XamlValueConverter.
Example fix
// before
var vc = new XamlValueConverter<ValueSerializer>(typeof(MyTypeConverter), targetType);
var inst = vc.ConverterInstance; // throws: MyTypeConverter is not a ValueSerializer
// after
if (typeof(ValueSerializer).IsAssignableFrom(typeof(MyValueSerializer)))
var vc = new XamlValueConverter<ValueSerializer>(typeof(MyValueSerializer), targetType); Defensive patterns
Strategy: type-guard
Validate before calling
if (converterType != null && !typeof(TConverterBase).IsAssignableFrom(converterType))
throw new ArgumentException("converterType mismatch");
var vc = new XamlValueConverter<TConverterBase>(converterType, targetType, name); Type guard
static bool IsCompatible<TBase>(Type converterType)
=> converterType == null || typeof(TBase).IsAssignableFrom(converterType); Try / catch
try { return vc.ConverterInstance; }
catch (XamlSchemaException ex) { /* log converter type mismatch */ return null; } Prevention
- Verify typeof(TConverterBase).IsAssignableFrom(converterType) before constructing.
- Pair converter types with the correct generic parameter (TypeConverter vs ValueSerializer).
When it happens
Trigger: Constructing an XamlValueConverter<ValueSerializer> with a converterType that derives from TypeConverter rather than ValueSerializer (or vice versa). Accessing ConverterInstance triggers the lazy CreateInstance.
Common situations: Schema-context code that pairs a converter type with the wrong TConverterBase generic parameter — e.g. assigning a TypeConverter-derived type to a ValueConverter-targeted XamlValueConverter. Incorrect custom XamlSchemaContext.GetXamlValueConverter overrides that return mismatched converter types.
Related errors
- Either of converterType, targetType or name must be non-null
- typeArguments array contains one or more null XamlTypeName
- Namespace must be set before calling ToString method.
- Name must be set before calling ToString method.
- Could not lookup prefix for namespace '{0}'
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/27f7bba08155b2a6.
Report an issue: GitHub.