{"record":{"id":"eda066b5284255da","repo":"unoplatform/uno","slug":"writer","errorCode":null,"errorMessage":"writer","messagePattern":"writer","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlServices.cs","lineNumber":100,"sourceCode":"\t\t\tusing (var xw = XmlWriter.Create (stream, new XmlWriterSettings () { OmitXmlDeclaration = true, Indent = true }))\n\t\t\t\tSave (xw, instance);\n\t\t}\n\n\t\tpublic static void Save (TextWriter writer, object instance)\n\t\t{\n\t\t\tusing (var xw = XmlWriter.Create (writer, new XmlWriterSettings () { OmitXmlDeclaration = true, Indent = true }))\n\t\t\t\tSave (xw, instance);\n\t\t}\n\n\t\tpublic static void Save (XmlWriter writer, object instance)\n\t\t{\n\t\t\tSave (new XamlXmlWriter (writer, new XamlSchemaContext ()), instance);\n\t\t}\n\n\t\tpublic static void Save (XamlWriter writer, object instance)\n\t\t{\n\t\t\tif (writer == null)\n\t\t\t\tthrow new ArgumentNullException (\"writer\");\n\t\t\tvar r = new XamlObjectReader (instance, writer.SchemaContext);\n\t\t\tTransform (r, writer);\n\t\t}\n\n\t\tpublic static void Transform (XamlReader xamlReader, XamlWriter xamlWriter)\n\t\t{\n\t\t\tTransform (xamlReader, xamlWriter, true);\n\t\t}\n\n\t\tpublic static void Transform (XamlReader xamlReader, XamlWriter xamlWriter, bool closeWriter)\n\t\t{\n\t\t\tif (xamlReader == null)\n\t\t\t\tthrow new ArgumentNullException (\"xamlReader\");\n\t\t\tif (xamlWriter == null)\n\t\t\t\tthrow new ArgumentNullException (\"xamlWriter\");\n\n\t\t\tif (xamlReader.NodeType == XamlNodeType.None)\n\t\t\t\txamlReader.Read ();","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlServices.cs#L82-L118","documentation":"XamlServices.Save(XamlWriter, object) throws ArgumentNullException('writer') when the XamlWriter argument is null. Save wraps the writer with a XamlObjectReader and calls Transform, so it cannot proceed without a destination writer.","triggerScenarios":"Passing a null XamlWriter to Save, commonly from a code path where the writer was conditionally created (e.g. only when a file could be opened) but Save is called unconditionally.","commonSituations":"Wrapping Save in a using/dispose block where the writer creation failed silently; refactoring that removed writer instantiation; tests passing null to verify argument validation.","solutions":["Null-check the XamlWriter before calling Save and surface a clear error or skip serialization.","Ensure the writer factory never returns null — if construction fails it should throw rather than return null.","Prefer the Save(TextWriter)/Save(XmlWriter)/Save(string) overloads which create the writer internally when you only need standard output."],"exampleFix":"// before\nXamlServices.Save((XamlWriter) writer, instance);\n\n// after\nif (writer == null) throw new ArgumentNullException(nameof(writer));\nXamlServices.Save(writer, instance);","handlingStrategy":"validation","validationCode":"if (writer == null) throw new ArgumentNullException(nameof(writer));\nXamlServices.Save(writer, instance);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use nullable reference types on writer variables so null is a compile error.","Construct the writer immediately before Save and let construction throw on failure rather than returning null.","Prefer Save(TextWriter/XmlWriter/string) overloads when standard output suffices."],"tags":["xaml","argument-null","xamlservices","serialization"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}