unoplatform/uno · error · ArgumentNullException
xamlWriter
Error message
xamlWriter
What it means
XamlServices.Transform(XamlReader, XamlWriter, bool) throws ArgumentNullException('xamlWriter') when the writer argument is null. Without a destination writer the transform has nowhere to emit nodes, so it fails fast.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlServices.cs:115
public static void Save (XamlWriter writer, object instance)
{
if (writer == null)
throw new ArgumentNullException ("writer");
var r = new XamlObjectReader (instance, writer.SchemaContext);
Transform (r, writer);
}
public static void Transform (XamlReader xamlReader, XamlWriter xamlWriter)
{
Transform (xamlReader, xamlWriter, true);
}
public static void Transform (XamlReader xamlReader, XamlWriter xamlWriter, bool closeWriter)
{
if (xamlReader == null)
throw new ArgumentNullException ("xamlReader");
if (xamlWriter == null)
throw new ArgumentNullException ("xamlWriter");
if (xamlReader.NodeType == XamlNodeType.None)
xamlReader.Read ();
while (!xamlReader.IsEof) {
xamlWriter.WriteNode (xamlReader);
xamlReader.Read ();
}
if (closeWriter)
xamlWriter.Close ();
}
}
}
View on GitHub (pinned to 0418340488)
Solutions
- Null-check the writer before calling Transform and surface the upstream failure.
- Make the writer factory throw on construction failure rather than return null.
- Prefer XamlServices.Save which manages writer construction internally.
Example fix
// before XamlServices.Transform(reader, writer); // after if (writer == null) throw new ArgumentNullException(nameof(writer)); XamlServices.Transform(reader, writer);
Defensive patterns
Strategy: validation
Validate before calling
if (xamlWriter == null) throw new ArgumentNullException(nameof(xamlWriter)); XamlServices.Transform(xamlReader, xamlWriter);
Prevention
- Make writer factories throw on construction failure instead of returning null.
- Enable nullable reference types to catch null at compile time.
When it happens
Trigger: Passing a null XamlWriter into Transform, typically when the writer was constructed conditionally (e.g. only when an output stream opened successfully).
Common situations: Output setup failure swallowed and null propagated into Transform; refactoring that removed writer creation; tests verifying guard behavior.
Related errors
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/6a13c407a3d325d2.
Report an issue: GitHub.