{"record":{"id":"c81c4089854e61aa","repo":"unoplatform/uno","slug":"schemacontext-c81c40","errorCode":null,"errorMessage":"schemaContext","messagePattern":"schemaContext","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectReader.cs","lineNumber":79,"sourceCode":"\t\tpublic XamlObjectReader (object instance)\n\t\t\t: this (instance, new XamlSchemaContext (null, null), null)\n\t\t{\n\t\t}\n\n\t\tpublic XamlObjectReader (object instance, XamlObjectReaderSettings settings)\n\t\t\t: this (instance, new XamlSchemaContext (null, null), settings)\n\t\t{\n\t\t}\n\n\t\tpublic XamlObjectReader (object instance, XamlSchemaContext schemaContext)\n\t\t\t: this (instance, schemaContext, null)\n\t\t{\n\t\t}\n\n\t\tpublic XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)\n\t\t{\n\t\t\tif (schemaContext == null)\n\t\t\t\tthrow new ArgumentNullException (\"schemaContext\");\n\t\t\t// FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.\n\t\t\tif (instance is Type)\n\t\t\t\tinstance = new TypeExtension ((Type) instance);\n\n\t\t\t// See also Instance property for this weirdness.\n\t\t\tthis.root_raw = instance;\n\t\t\tinstance = TypeExtensionMethods.GetExtensionWrapped (instance);\n\t\t\tthis.root = instance;\n\n\t\t\tsctx = schemaContext;\n//\t\t\tthis.settings = settings;\n\n\t\t\t// check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)\n\t\t\tif (instance != null) {\n\t\t\t\tvar type = new InstanceContext (instance).GetRawValue ().GetType ();\n\t\t\t\tif (!type.IsPublic)\n\t\t\t\t\tthrow new XamlObjectReaderException (String.Format (CultureInfo.InvariantCulture, \"instance type '{0}' must be public and non-nested.\", type));\n\t\t\t\tvar xt = SchemaContext.GetXamlType (type);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectReader.cs#L61-L97","documentation":"Thrown by the XamlObjectReader(object, XamlSchemaContext, XamlObjectReaderSettings) constructor when schemaContext is null. XamlObjectReader needs a schema context to resolve XamlType and XamlMember identity for the object graph it reads; a null context makes type resolution impossible and is rejected with ArgumentNullException.","triggerScenarios":"Constructing new XamlObjectReader(obj, null) or new XamlObjectReader(obj, null, settings) — passing a null schema context. Typically from a variable that was conditionally assigned or from a factory returning null.","commonSituations":"XAML serialization entry points that accept an optional schema context and default it incorrectly to null. Code that constructs XamlObjectReader without reading the schema context from a parent reader/writer.","solutions":["Pass a valid XamlSchemaContext: new XamlObjectReader(obj, new XamlSchemaContext()).","Reuse the schema context from a related reader/writer to maintain consistency.","Guard: var sctx = providedSchemaContext ?? new XamlSchemaContext();"],"exampleFix":"// before\nvar reader = new XamlObjectReader(myObject, schemaContext); // null\n\n// after\nvar reader = new XamlObjectReader(myObject, schemaContext ?? new XamlSchemaContext());","handlingStrategy":"validation","validationCode":"var ctx = schemaContext ?? new XamlSchemaContext();\nvar reader = new XamlObjectReader(obj, ctx);","typeGuard":null,"tryCatchPattern":"try { var reader = new XamlObjectReader(obj, sctx); }\ncatch (ArgumentNullException) { var reader = new XamlObjectReader(obj, new XamlSchemaContext()); }","preventionTips":["Always pass a non-null XamlSchemaContext to XamlObjectReader.","Reuse a context from related reader/writer for consistency."],"tags":["xaml","argument-null","object-reader","schema-context","uno-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}