unoplatform/uno · error · ArgumentNullException

xamlType

Error message

xamlType

What it means

XamlWriterInternalBase.WriteStartObject throws ArgumentNullException('xamlType') when a null XamlType is written. The XamlType is pushed onto the object state stack and used to drive member/type lookups, so a null would break the writer state machine.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlWriterInternalBase.cs:165

			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 ();
		}
		
		public void WriteValue (object value)
		{
			manager.Value ();

			OnWriteValue (value);
		}
		
		public void WriteStartMember (XamlMember property)
		{

View on GitHub (pinned to 0418340488)

Solutions

  1. Ensure the XamlType is resolved before writing StartObject; if resolution failed, surface that error instead of writing null.
  2. Validate reader.Type is non-null when NodeType == StartObject before forwarding to WriteStartObject.
  3. In custom readers, never return null from the Type property on a StartObject node.

Example fix

// before
if (reader.NodeType == XamlNodeType.StartObject)
    writer.WriteStartObject(reader.Type); // reader.Type may be null

// after
if (reader.NodeType == XamlNodeType.StartObject && reader.Type != null)
    writer.WriteStartObject(reader.Type);
Defensive patterns

Strategy: type-guard

Validate before calling

if (reader.NodeType == XamlNodeType.StartObject && reader.Type != null)
    writer.WriteStartObject(reader.Type);

Type guard

static bool CanWriteStartObject(XamlReader r) => r.NodeType == XamlNodeType.StartObject && r.Type is not null;

Prevention

When it happens

Trigger: Writing a StartObject node for a type that resolved to null — e.g. forwarding a node from a reader whose Type property returned null (reader not positioned on StartObject, or type resolution failed silently).

Common situations: Custom XamlReader that returns null from Type when NodeType is StartObject; pipeline code that synthesizes StartObject nodes without a resolved type; tests of the validation guard.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/e10b5a78c3904ef6. Report an issue: GitHub.