{"record":{"id":"c4ff77fad2d348cb","repo":"dotnet/wpf","slug":"sr-objectreader-typenotvisible","errorCode":null,"errorMessage":"SR.ObjectReader_TypeNotVisible","messagePattern":"SR\\.ObjectReader_TypeNotVisible","errorType":"exception","errorClass":"XamlObjectReaderException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs","lineNumber":2654,"sourceCode":"\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)\n            {\n                return Runtime.CanConvertTo(TypeDescriptorContext, converter, type);\n            }\n\n            public bool CanRoundTripString(TypeConverter converter)\n            {\n                if (converter is ReferenceConverter)\n                {\n                    return false;\n                } // ReferenceConverter lies.\n\n                return Runtime.CanConvertFrom<string>(TypeDescriptorContext, converter) &&","sourceCodeStart":2636,"sourceCodeEnd":2672,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs#L2636-L2672","documentation":"XamlObjectReader throws this when it resolves a CLR type via GetXamlType but that type is not visible to the local assembly being processed (IsVisibleTo(LocalAssembly) fails and the type is not a Type). This guards XAML reflection against non-public types, since serializing/deserializing non-visible types would bypass accessibility rules.","triggerScenarios":"Calling XamlObjectReader over a node stream or object graph that references an internal/private CLR type while a LocalAssembly is set (e.g. when reading XAML produced by a partial-trust XamlXmlWriter save or within the XamlDesigner factory path).","commonSituations":"Developer marks a view-model or control class 'internal' but references it from XAML; saving and reloading XAML in a designer/partial-trust sandbox; assembly-split refactors making a type non-public in the local assembly.","solutions":["Make the referenced CLR type public","Check the XAML for references to types in the local assembly that are internal and expose public wrappers","Verify LocalAssembly is set correctly; if the type genuinely belongs to another visible assembly, ensure the schema context resolves it from the right assembly","If the node intentionally represents a System.Type, use x:Type so the typeof(Type) exemption applies"],"exampleFix":"// before\ninternal class MyConverter { ... }\n// after\npublic class MyConverter { ... }","handlingStrategy":"validation","validationCode":"if (!clrType.IsPublic && localAssembly != null && clrType.Assembly == localAssembly && !typeof(Type).IsAssignableFrom(clrType)) throw new InvalidOperationException($\"Type {clrType.FullName} is not visible to the local assembly.\");","typeGuard":"bool IsVisibleTo(Type t, Assembly local) => typeof(Type).IsAssignableFrom(t) || (t.IsNested ? t.IsVisible : t.IsPublic);","tryCatchPattern":null,"preventionTips":["Keep XAML-referenced types public","Test XAML load/save round-trips after changing type accessibility","Review internal->protected refactors that affect XAML-visible types"],"tags":["xaml","reflection","accessibility","wpf"],"backgroundTag":"permission-denied","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"}