{"record":{"id":"a61cc8b0ab166953","repo":"dotnet/wpf","slug":"sr-notsupportedonunknowntype","errorCode":null,"errorMessage":"SR.NotSupportedOnUnknownType","messagePattern":"SR\\.NotSupportedOnUnknownType","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs","lineNumber":251,"sourceCode":"                {\n                    Type type = _xamlType.UnderlyingType.UnderlyingSystemType;\n                    _isPublic = type.IsVisible ? ThreeValuedBool.True : ThreeValuedBool.False;\n                }\n\n                return _isPublic == ThreeValuedBool.True;\n            }\n        }\n\n        private bool IsUnknown\n        {\n            get { return _xamlType is null || _xamlType.UnderlyingType is null; }\n        }\n\n        private void ThrowIfUnknown()\n        {\n            if (IsUnknown)\n            {\n                throw new NotSupportedException(SR.NotSupportedOnUnknownType);\n            }\n        }\n\n        private static class DefaultCtorXamlActivator\n        {\n            private static ThreeValuedBool s_securityFailureWithCtorDelegate;\n            private static ConstructorInfo s_actionCtor =\n                typeof(Action<object>).GetConstructor(new Type[] { typeof(object), typeof(IntPtr) });\n\n            public static object CreateInstance(XamlTypeInvoker type)\n            {\n                if (!EnsureConstructorDelegate(type))\n                {\n                    return null;\n                }\n\n                object inst = CallCtorDelegate(type);\n                return inst;","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs#L233-L269","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninvoker.CreateInstance(args);\n// after\nif (!invoker.IsUnknown) { invoker.CreateInstance(args); } else { /* handle unresolvable type */ }","handlingStrategy":"validation","validationCode":"if (xamlType.UnderlyingType is null || invoker.IsUnknown) { /* skip or resolve */ }","typeGuard":"static bool IsUsable(XamlType t) => !t.IsUnknown && t.UnderlyingType is not null;","tryCatchPattern":"try { invoker.CreateInstance(null); } catch (NotSupportedException) { /* type could not be resolved */ }","preventionTips":["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."],"tags":["xaml","notsupported","unknown-type","resolution"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}