dotnet/wpf · error · NotSupportedException
SR.NotSupportedOnUnknownType
Error message
SR.NotSupportedOnUnknownType
What it means
XamlTypeInvoker.ThrowIfUnknown throws NotSupportedException('NotSupportedOnUnknownType') whenever an operation is attempted on the sentinel Unknown invoker — the invoker attached to a XamlType with no resolvable underlying CLR type. XAML can describe types it cannot resolve (unknown namespaces, missing assemblies); creating instances or mutating them is meaningless, so System.Xaml rejects these calls uniformly.
Solutions
- Fix the XAML namespace/assembly mapping so the type resolves (correct clr-namespace and assembly names, ensure the assembly is referenced).
- Guard with xamlTypeInvoker.IsUnknown (or xamlType.UnderlyingType != null) before invoking operations on unknown types.
- Catch NotSupportedException when processing untrusted/partially resolvable XAML and skip or defer those nodes.
- Provide a XamlSchemaContext with custom lookup/assembly resolution to map unknown names to known types.
Example fix
// before
invoker.CreateInstance(args);
// after
if (!invoker.IsUnknown) { invoker.CreateInstance(args); } else { /* handle unresolvable type */ } Defensive patterns
Strategy: validation
Validate before calling
if (xamlType.UnderlyingType is null || invoker.IsUnknown) { /* skip or resolve */ } Type guard
static bool IsUsable(XamlType t) => !t.IsUnknown && t.UnderlyingType is not null;
Try / catch
try { invoker.CreateInstance(null); } catch (NotSupportedException) { /* type could not be resolved */ } Prevention
- Validate clr-namespace/assembly mappings in XAML before loading.
- Reference all assemblies containing XAML-used types at runtime.
- Check XamlType.IsUnknown when walking schemas that may include placeholders.
- Provide custom schema-context lookup for renamed or moved types.
When it happens
Trigger: Calling AddToCollection, AddToDictionary, CreateInstance, or GetItems on a XamlTypeInvoker whose IsUnknown is true, i.e. obtained from XamlType.For(string, ...) with an unresolvable name, a XamlType whose UnderlyingType is null and no lookup delegate resolved it, or from XamlType of an unrecognized XML namespace.
Common situations: Loading XAML referencing types from assemblies not referenced/deployed at runtime; typos in clr-namespace/assembly mappings; forward-declared or removed types in markup; tooling code walking a XAML schema that includes placeholder unknown types.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- NotSupportedException(SR.MissingCaseXamlNodes)
- SR.OnlySupportedOnCollectionsAndDictionaries
- SR.OnlySupportedOnDictionaries
- throw new NotSupportedException() in ICollection
- ' '.' ' is a property without a getter and is not a valid…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a61cc8b0ab166953.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs:251
{
Type type = _xamlType.UnderlyingType.UnderlyingSystemType;
_isPublic = type.IsVisible ? ThreeValuedBool.True : ThreeValuedBool.False;
}
return _isPublic == ThreeValuedBool.True;
}
}
private bool IsUnknown
{
get { return _xamlType is null || _xamlType.UnderlyingType is null; }
}
private void ThrowIfUnknown()
{
if (IsUnknown)
{
throw new NotSupportedException(SR.NotSupportedOnUnknownType);
}
}
private static class DefaultCtorXamlActivator
{
private static ThreeValuedBool s_securityFailureWithCtorDelegate;
private static ConstructorInfo s_actionCtor =
typeof(Action<object>).GetConstructor(new Type[] { typeof(object), typeof(IntPtr) });
public static object CreateInstance(XamlTypeInvoker type)
{
if (!EnsureConstructorDelegate(type))
{
return null;
}
object inst = CallCtorDelegate(type);
return inst;View on GitHub (pinned to 81131a70a4)