unoplatform/uno · error · NotSupportedException
Current operation is valid only when the underlying type on
Error message
Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}' What it means
Thrown by XamlTypeInvoker.ThrowIfUnknown when the invoker's type is null (UnknownInvoker) or when type.UnderlyingType is null (the XamlType has no backing CLR type). Several operations (CreateInstance, and the contract for collection/dictionary manipulation) require a real CLR type to reflect over. With an unknown or unbacked XamlType, reflection is impossible.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs:60
}
protected XamlTypeInvoker ()
{
}
public XamlTypeInvoker (XamlType type)
{
if (type == null)
throw new ArgumentNullException ("type");
this.type = type;
}
XamlType type;
void ThrowIfUnknown ()
{
if (type == null || type.UnderlyingType == null)
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}'", type));
}
public EventHandler<XamlSetMarkupExtensionEventArgs> SetMarkupExtensionHandler {
get { return type == null ? null : type.SetMarkupExtensionHandler; }
}
public EventHandler<XamlSetTypeConverterEventArgs> SetTypeConverterHandler {
get { return type == null ? null : type.SetTypeConverterHandler; }
}
public virtual void AddToCollection (object instance, object item)
{
if (instance == null)
throw new ArgumentNullException ("instance");
if (item == null)
throw new ArgumentNullException ("item");
var ct = instance.GetType ();View on GitHub (pinned to 0418340488)
Solutions
- Ensure the XamlType has a non-null UnderlyingType before invoking reflection operations — check `xamlType.UnderlyingType != null`.
- Do not call CreateInstance or collection operations on UnknownInvoker.
- Fix type loading: add the assembly reference, fix xmlns namespace to a CLR namespace, or disable trimming for the relevant types.
- Differentiate schema-only types from reflectable types in your writer and skip reflection ops on the former.
Example fix
// before
object obj = xamlType.Invoker.CreateInstance(args);
// after
if (xamlType.UnderlyingType == null) {
throw new InvalidOperationException("Cannot instantiate XamlType with no underlying CLR type: " + xamlType);
}
object obj = xamlType.Invoker.CreateInstance(args); Defensive patterns
Strategy: validation
Validate before calling
// before reflection operations
if (xamlType.UnderlyingType == null) {
throw new InvalidOperationException("XamlType has no underlying CLR type; cannot use reflection invoker.");
} Prevention
- Never call CreateInstance or collection ops on UnknownInvoker.
- Ensure referenced types are loaded; fix xmlns-to-CLR-namespace mappings.
- Under trimming, preserve types needed for reflection.
When it happens
Trigger: Calling invoker operations on XamlTypeInvoker.UnknownInvoker, or on an invoker for a XamlType whose UnderlyingType is null (e.g. a XamlType built purely from name without CLR type info, common for generic/unknown types in the schema). CreateInstance calls ThrowIfUnknown directly.
Common situations: XAML referencing types not present in loaded assemblies; using a XamlSchemaContext that returns schema-only XamlTypes; dynamic/XAML-first scenarios where the CLR type is intentionally unknown; trimming that removed the underlying type.
Related errors
- Attempt to set value from read-only property {0}
- type
- Non-collection type '{0}' does not support this operation
- The collection type '{0}' does not have 'Add' method
- instance
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/67a08f693688fb90.
Report an issue: GitHub.