{"record":{"id":"a5ac3f439886b0e4","repo":"dotnet/wpf","slug":"sr-objectreadertypenotallowed","errorCode":null,"errorMessage":"SR.ObjectReaderTypeNotAllowed","messagePattern":"SR\\.ObjectReaderTypeNotAllowed","errorType":"exception","errorClass":"XamlObjectReaderException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs","lineNumber":2642,"sourceCode":"                    }\n\n                    if (prefix.Length == 0)\n                    {\n                        XmlConvert.VerifyNCName(prefix);\n                    }\n                }\n\n                namespaceToPrefixMap.Add(ns, prefix);\n                prefixToNamespaceMap.Add(prefix, ns);\n                return prefix;\n            }\n\n            public XamlType GetXamlType(Type clrType)\n            {\n                XamlType result = schemaContext.GetXamlType(clrType);\n                if (result is null)\n                {\n                    throw new XamlObjectReaderException(SR.Format(SR.ObjectReaderTypeNotAllowed,\n                        schemaContext.GetType(), clrType));\n                }\n\n                return result;\n            }\n\n            public XamlType LocalAssemblyAwareGetXamlType(Type clrType)\n            {\n                XamlType result = GetXamlType(clrType);\n                if (!result.IsVisibleTo(LocalAssembly) && !typeof(Type).IsAssignableFrom(clrType))\n                {\n                    throw new XamlObjectReaderException(SR.Format(SR.ObjectReader_TypeNotVisible, clrType.FullName));\n                }\n\n                return result;\n            }\n\n            public bool CanConvertTo(TypeConverter converter, Type type)","sourceCodeStart":2624,"sourceCodeEnd":2660,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs#L2624-L2660","documentation":"The XamlObjectReader's schema context throws this when GetXamlType(Type) cannot find a XamlType for the given CLR type: the schema context does not allow that type. This means the type is outside the set of types the reader's SchemaContext is configured to load (e.g. type not in the local assembly context's allowed assemblies).","triggerScenarios":"XamlObjectReader.SchemaContext.GetXamlType(clrType) called (directly or indirectly) with a CLR type that the context's assembly set/permission set does not include — e.g. types outside LocalAssembly contexts or non-XAML-compatible types.","commonSituations":"Partial-trust XAML loading where the type's assembly is not in the allowed list; using XamlObjectReader with a restricted schema context while the graph contains types from other assemblies; plugin assemblies not registered with the context.","solutions":["Add the type's assembly to the schema context's allowed assemblies (or use a full-trust/default XamlSchemaContext)","Use XamlSchemaContext with appropriate XamlSchemaContextSettings/assembly resolution so the type resolves","Replace out-of-context types in the graph with allowed ones before reading","Catch XamlObjectReaderException and fall back to a context configured for that type"],"exampleFix":"// before\nvar sc = new XamlSchemaContext(new[] { typeof(MainWindow).Assembly });\n// after: include the assembly defining the type\nvar sc = new XamlSchemaContext(new[] { typeof(MainWindow).Assembly, typeof(Foreign.Widget).Assembly });","handlingStrategy":"try-catch","validationCode":"var sc = new XamlSchemaContext(relevantAssemblies);\nvar xt = sc.GetXamlType(clrType);\nif (xt == null) throw new InvalidOperationException($\"{clrType} not resolvable in schema context\");","typeGuard":"bool TypeAllowed(XamlSchemaContext sc, Type t) => sc.GetXamlType(t) != null;","tryCatchPattern":"try { var xt = reader.SchemaContext.GetXamlType(clrType); } catch (XamlObjectReaderException ex) when (ex.Message.Contains(\"TypeNotAllowed\")) { /* widen context assembly list */ }","preventionTips":["Register every assembly referenced by the object graph with the schema context","Pre-check types with schemaContext.GetXamlType before reading","Avoid partial-trust/restricted contexts unless the type set is fully known"],"tags":["xaml","schema-context","assembly"],"backgroundTag":"class-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}