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

  1. Fix the XAML namespace/assembly mapping so the type resolves (correct clr-namespace and assembly names, ensure the assembly is referenced).
  2. Guard with xamlTypeInvoker.IsUnknown (or xamlType.UnderlyingType != null) before invoking operations on unknown types.
  3. Catch NotSupportedException when processing untrusted/partially resolvable XAML and skip or defer those nodes.
  4. 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

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


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)