unoplatform/uno · error · ArgumentNullException
namespaceDeclaration
Error message
namespaceDeclaration
What it means
XamlWriterInternalBase.WriteNamespace throws ArgumentNullException('namespaceDeclaration') when a null NamespaceDeclaration is written. The declaration (prefix+namespace pair) is added to the namespaces list and forwarded to OnWriteNamespace, so a null entry would corrupt the namespace manager.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlWriterInternalBase.cs:154
}
public void WriteGetObject ()
{
manager.GetObject ();
var xm = CurrentMember;
var state = new ObjectState () {Type = xm.Type, IsGetObject = true};
object_states.Push (state);
OnWriteGetObject ();
}
public void WriteNamespace (NamespaceDeclaration namespaceDeclaration)
{
if (namespaceDeclaration == null)
throw new ArgumentNullException ("namespaceDeclaration");
manager.Namespace ();
namespaces.Add (namespaceDeclaration);
OnWriteNamespace (namespaceDeclaration);
}
public void WriteStartObject (XamlType xamlType)
{
if (xamlType == null)
throw new ArgumentNullException ("xamlType");
manager.StartObject ();
var cstate = new ObjectState () {Type = xamlType};
object_states.Push (cstate);
OnWriteStartObject ();View on GitHub (pinned to 0418340488)
Solutions
- Filter out or reject null NamespaceDeclaration before calling WriteNamespace.
- If you control the reader, ensure it never yields null namespace nodes.
- Use XamlServices.Transform which forwards reader nodes through the writer's own WriteNode dispatcher.
Example fix
// before writer.WriteNamespace(decl); // after if (decl != null) writer.WriteNamespace(decl);
Defensive patterns
Strategy: validation
Validate before calling
if (namespaceDeclaration != null) writer.WriteNamespace(namespaceDeclaration);
Type guard
bool IsValid(NamespaceDeclaration? d) => d != null && !string.IsNullOrEmpty(d.Namespace);
Prevention
- Filter null declarations in custom pipelines before forwarding to the writer.
- Ensure custom XamlReaders never emit null NamespaceDeclaration nodes.
When it happens
Trigger: Calling WriteNamespace(null) directly, or passing a NamespaceDeclaration obtained from a reader that yielded null (e.g. a buggy custom XamlReader).
Common situations: Custom XamlReader implementations that emit null NamespaceDeclarations; pipeline code forwarding declarations without filtering nulls; tests asserting validation.
Related errors
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/d04100dfccce7633.
Report an issue: GitHub.