{"record":{"id":"b90b40d1c376e294","repo":"unoplatform/uno","slug":"xamlreader","errorCode":null,"errorMessage":"xamlReader","messagePattern":"xamlReader","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlServices.cs","lineNumber":56,"sourceCode":"\t\tpublic static Object Load (Stream stream)\n\t\t{\n\t\t\treturn Load (new XamlXmlReader (stream));\n\t\t}\n\n\t\tpublic static Object Load (TextReader textReader)\n\t\t{\n\t\t\treturn Load (new XamlXmlReader (textReader));\n\t\t}\n\n\t\tpublic static Object Load (XmlReader xmlReader)\n\t\t{\n\t\t\treturn Load (new XamlXmlReader (xmlReader));\n\t\t}\n\n\t\tpublic static Object Load (XamlReader xamlReader)\n\t\t{\n\t\t\tif (xamlReader == null)\n\t\t\t\tthrow new ArgumentNullException (\"xamlReader\");\n\t\t\tvar w = new XamlObjectWriter (xamlReader.SchemaContext);\n\t\t\tTransform (xamlReader, w);\n\t\t\treturn w.Result;\n\t\t}\n\n\t\tpublic static Object Parse (string xaml)\n\t\t{\n\t\t\treturn Load (new StringReader (xaml));\n\t\t}\n\n\t\tpublic static string Save (object instance)\n\t\t{\n\t\t\tvar sw = new StringWriter ();\n\t\t\tSave (sw, instance);\n\t\t\treturn sw.ToString ();\n\t\t}\n\n\t\tpublic static void Save (string fileName, object instance)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlServices.cs#L38-L74","documentation":"XamlServices.Load(XamlReader) throws ArgumentNullException('xamlReader') when the caller passes a null XamlReader. The method needs a reader to construct a XamlObjectWriter against the reader's SchemaContext and then drive Transform, so a null reader has no schema context to use.","triggerScenarios":"Calling XamlServices.Load((XamlReader)null), or passing a variable that was conditionally assigned null (e.g. a factory method returned null because the input stream was empty). Also when a wrapper returns null instead of a XamlXmlReader.","commonSituations":"Defensive code paths that create a reader only when a condition holds but unconditionally call Load; refactoring that changes a method to return null on error; unit tests feeding null to exercise error handling.","solutions":["Null-check the XamlReader before calling Load and handle the null case explicitly (return early or throw a domain-specific exception).","Ensure the factory/builder that produces the XamlReader never returns null — return a XamlXmlReader over an empty stream instead, or throw at the source.","If the input is a string/XmlReader, prefer the typed overloads Load(string)/Load(XmlReader) which construct the reader internally."],"exampleFix":"// before\nXamlServices.Load((XamlReader) reader);\n\n// after\nif (reader == null) throw new ArgumentNullException(nameof(reader));\nXamlServices.Load(reader);","handlingStrategy":"validation","validationCode":"if (xamlReader == null) throw new ArgumentNullException(nameof(xamlReader));\nXamlServices.Load(xamlReader);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark XamlReader-producing factory methods as non-nullable (C# nullable reference types) so null is caught at compile time.","Prefer the typed overloads XamlServices.Load(string)/Load(XmlReader) when you have raw input — they construct the reader for you."],"tags":["xaml","argument-null","xamlservices"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}