{"record":{"id":"04514c3e427e6842","repo":"unoplatform/uno","slug":"schemacontext-04514c","errorCode":null,"errorMessage":"schemaContext","messagePattern":"schemaContext","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":82,"sourceCode":"*/\n\n#if DOTNET\nnamespace Mono.Xaml\n#else\nnamespace Uno.Xaml\n#endif\n{\n\tpublic class XamlObjectWriter : XamlWriter, IXamlLineInfoConsumer\n\t{\n\t\tpublic XamlObjectWriter (XamlSchemaContext schemaContext)\n\t\t\t: this (schemaContext, null)\n\t\t{\n\t\t}\n\n\t\tpublic XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)\n\t\t{\n\t\t\tif (schemaContext == null)\n\t\t\t\tthrow new ArgumentNullException (\"schemaContext\");\n\t\t\tthis.sctx = schemaContext;\n\t\t\tthis.settings = settings ?? new XamlObjectWriterSettings ();\n\t\t\tvar manager = new XamlWriterStateManager<XamlObjectWriterException, XamlObjectWriterException> (false);\n\t\t\tintl = new XamlObjectWriterInternal (this, sctx, manager);\n\t\t}\n\n\t\tXamlSchemaContext sctx;\n\t\tXamlObjectWriterSettings settings;\n\n\t\tXamlObjectWriterInternal intl;\n\n\t\t//int line, column;\n\t\tbool lineinfo_was_given;\n\n\t\tinternal XamlObjectWriterSettings Settings {\n\t\t\tget { return settings; }\n\t\t}\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L64-L100","documentation":"Thrown by the XamlObjectWriter constructor when the supplied XamlSchemaContext is null. The schema context is the writer's only way to resolve XAML types, members, namespaces, and type converters, so it is mandatory. A null value makes every subsequent write operation undefined, so the constructor fails fast.","triggerScenarios":"Calling `new XamlObjectWriter(null)` or `new XamlObjectWriter(null, settings)`, i.e. invoking the constructor with a null first argument.","commonSituations":"DI/factory wiring that forgot to register or resolve a XamlSchemaContext; test scaffolding that passes null as a placeholder; refactoring that removed the context's creation but left the call site.","solutions":["Pass a valid XamlSchemaContext, e.g. `new XamlSchemaContext()` or one built from the relevant assemblies: `new XamlSchemaContext(myAssemblies)`.","If constructing in a factory, null-check the incoming dependency and supply a default context before calling the constructor.","Register XamlSchemaContext in your DI container so it is never null at the call site."],"exampleFix":"// before\nvar writer = new XamlObjectWriter(null);\n// after\nvar writer = new XamlObjectWriter(new XamlSchemaContext());","handlingStrategy":"validation","validationCode":"if (schemaContext == null)\n    throw new InvalidOperationException(\"A XamlSchemaContext must be provided before constructing the writer.\");\nvar writer = new XamlObjectWriter(schemaContext);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct the XamlSchemaContext once at setup and inject it; never pass null placeholders.","Add a debug assertion at factory sites: Debug.Assert(schemaContext != null).","Register XamlSchemaContext in DI so call sites always receive a valid instance."],"tags":["xaml","null-argument","constructor","validation"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}