{"record":{"id":"7d93485cb456bb30","repo":"unoplatform/uno","slug":"the-value-for-0-property-is-null","errorCode":null,"errorMessage":"The value  for '{0}' property is null","messagePattern":"The value  for '(.+?)' property is null","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":264,"sourceCode":"\t\t\t\t\tstate.IsInstantiated = true;\n\t\t\t\t}\n\t\t\t\troot_state = state;\n\t\t\t}\n\t\t\tobject_states.Push (state);\n\t\t\tif (!state.Type.IsContentValue (service_provider))\n\t\t\t\tInitializeObjectIfRequired (true);\n\n\t\t\tstate.IsXamlWriterCreated = true;\n\t\t\tsource.OnBeforeProperties (state.Value);\n\t\t}\n\n\t\tprotected override void OnWriteGetObject ()\n\t\t{\n\t\t\tvar state = object_states.Pop ();\n\t\t\tvar xm = CurrentMember;\n\t\t\tvar instance = xm.Invoker.GetValue (object_states.Peek ().Value);\n\t\t\tif (instance == null)\n\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"The value  for '{0}' property is null\", xm.Name));\n\t\t\tstate.Value = instance;\n\t\t\tstate.IsInstantiated = true;\n\t\t\tobject_states.Push (state);\n\t\t}\n\n\t\tprotected override void OnWriteEndObject ()\n\t\t{\n\t\t\tInitializeObjectIfRequired (false); // this is required for such case that there was no StartMember call.\n\n\t\t\tvar state = object_states.Pop ();\n\t\t\tvar obj = state.Value;\n\t\t\t\n\t\t\tif (obj is MarkupExtension) {\n\t\t\t\ttry {\n\t\t\t\t\tobj = ((MarkupExtension) obj).ProvideValue (service_provider);\n\t\t\t\t} catch (XamlObjectWriterException) {\n\t\t\t\t\tthrow;\n\t\t\t\t} catch (Exception ex) {","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L246-L282","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic IList<Item> Items { get; } = null;\n// after\npublic IList<Item> Items { get; } = new List<Item>();","handlingStrategy":"validation","validationCode":"// Ensure any read-only collection/dictionary property returns a non-null instance.\npublic IList<Item> Items { get; } = new List<Item>();","typeGuard":null,"tryCatchPattern":"try { writer.WriteGetObject(); }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"is null\")) {\n    // the accessed property returned null; initialize its backing field.\n}","preventionTips":["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."],"tags":["xaml","null-value","get-object","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}