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
- Initialize the property's backing collection in the type's constructor so the getter never returns null.
- Avoid Get semantics on members that may legitimately be null.
- 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
- Initialize all read-only collection/dictionary backing fields in constructors or via initializers.
- Avoid x:GetObject semantics on members that may legitimately be null.
- Add a constructor-level invariant test that collection properties are non-null after construction.
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
- Member '{0}' is already written to current type '{1}'
- RootObjectInstance type '{0}' is not assignable to '{1}'
- An error occurred on getting provided value
- Specified static factory method '{0}' for type '{1}' was not
- Event {0} has no underlying member to attach event
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/7d93485cb456bb30.
Report an issue: GitHub.