unoplatform/uno · error · XamlObjectWriterException

The value for '{0}' property is null

Error message

The value  for '{0}' property is null

What it means

Thrown in OnWriteGetObject, which handles XAML 'Get' semantics (accessing an existing property value rather than creating one, used for read-only collection/dictionary properties and shared resources). The writer calls the member's invoker to fetch the current value; if it returns null there is nothing to populate, so it throws. Note the message contains a stray double space ('The value for').

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:264

					state.IsInstantiated = true;
				}
				root_state = state;
			}
			object_states.Push (state);
			if (!state.Type.IsContentValue (service_provider))
				InitializeObjectIfRequired (true);

			state.IsXamlWriterCreated = true;
			source.OnBeforeProperties (state.Value);
		}

		protected override void OnWriteGetObject ()
		{
			var state = object_states.Pop ();
			var xm = CurrentMember;
			var instance = xm.Invoker.GetValue (object_states.Peek ().Value);
			if (instance == null)
				throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "The value  for '{0}' property is null", xm.Name));
			state.Value = instance;
			state.IsInstantiated = true;
			object_states.Push (state);
		}

		protected override void OnWriteEndObject ()
		{
			InitializeObjectIfRequired (false); // this is required for such case that there was no StartMember call.

			var state = object_states.Pop ();
			var obj = state.Value;
			
			if (obj is MarkupExtension) {
				try {
					obj = ((MarkupExtension) obj).ProvideValue (service_provider);
				} catch (XamlObjectWriterException) {
					throw;
				} catch (Exception ex) {

View on GitHub (pinned to 0418340488)

Solutions

  1. Initialize the property's backing collection in the type's constructor so the getter never returns null.
  2. Avoid Get semantics on members that may legitimately be null.
  3. Make the property read-write and ensure it is assigned before Get access.

Example fix

// before
public IList<Item> Items { get; } = null;
// after
public IList<Item> Items { get; } = new List<Item>();
Defensive patterns

Strategy: validation

Validate before calling

// Ensure any read-only collection/dictionary property returns a non-null instance.
public IList<Item> Items { get; } = new List<Item>();

Try / catch

try { writer.WriteGetObject(); }
catch (XamlObjectWriterException ex) when (ex.Message.Contains("is null")) {
    // the accessed property returned null; initialize its backing field.
}

Prevention

When it happens

Trigger: A `<x:GetObject>`-style access (or programmatic WriteGetObject) on a property whose getter returns null — typically a read-only collection/dictionary property whose backing field was never initialized.

Common situations: Read-only `IList`/`IDictionary` auto-properties that default to null because the type's constructor did not create the collection; frozen/shared resources accessed before initialization.

Related errors


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