{"record":{"id":"82e9bdecb82fd482","repo":"unoplatform/uno","slug":"member-0-is-already-written-to-current-type","errorCode":null,"errorMessage":"Member '{0}' is already written to current type '{1}'","messagePattern":"Member '(.+?)' is already written to current type '(.+?)'","errorType":"exception","errorClass":"XamlDuplicateMemberException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":239,"sourceCode":"\t\tXamlObjectWriter source;\n\t\tXamlSchemaContext sctx;\n\t\tINameScope name_scope;\n\t\tList<NameFixupRequired> pending_name_references = new List<NameFixupRequired> ();\n\t\tAmbientProvider ambient_provider = new AmbientProvider ();\n\n\t\tpublic INameScope NameScope {\n\t\t\tget { return name_scope; }\n\t\t}\n\n\t\tpublic object Result { get; set; }\n\t\t\n\t\tprotected override void OnWriteStartObject ()\n\t\t{\n\t\t\tvar state = object_states.Pop ();\n\t\t\tif (object_states.Count > 0) {\n\t\t\t\tvar pstate = object_states.Peek ();\n\t\t\t\tif (CurrentMemberState.Value != null)\n\t\t\t\t\tthrow new XamlDuplicateMemberException (String.Format (CultureInfo.InvariantCulture, \"Member '{0}' is already written to current type '{1}'\", CurrentMember, pstate.Type));\n\t\t\t} else {\n\t\t\t\tvar obj = source.Settings.RootObjectInstance;\n\t\t\t\tif (obj != null) {\n\t\t\t\t\tif (state.Type.UnderlyingType != null && !state.Type.UnderlyingType.IsAssignableFrom (obj.GetType ()))\n\t\t\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"RootObjectInstance type '{0}' is not assignable to '{1}'\", obj.GetType (), state.Type));\n\t\t\t\t\tstate.Value = obj;\n\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","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L221-L257","documentation":"A XamlDuplicateMemberException thrown in OnWriteStartObject when the current member state already holds a value. XAML forbids assigning the same scalar property twice on one object instance — each member may be written once between StartMember/EndMember. The guard fires the moment a second StartObject is begun while the parent's current member is already populated.","triggerScenarios":"XAML that sets the same property twice on one element (e.g. two `<Button.Content>` children), or programmatic use of the XAML writer that calls WriteStartMember for the same member twice without an intervening WriteEndMember.","commonSituations":"Hand-edited or code-generated XAML with duplicated property elements; merged styles/dictionaries that re-apply a property; treating a scalar property like a collection and appending to it.","solutions":["Remove the duplicate property element/assignment in the XAML so the member is set exactly once.","If writing the object graph programmatically, call WriteEndMember() before starting the same member again.","For collection-valued properties, assign multiple items as children of the collection property rather than re-declaring the property itself."],"exampleFix":"<!-- before -->\n<Button>\n  <Button.Content>A</Button.Content>\n  <Button.Content>B</Button.Content>\n</Button>\n<!-- after -->\n<Button Content=\"A\" />","handlingStrategy":"validation","validationCode":"// Validate XAML does not repeat the same property element before writing.\n// If building the node stream programmatically, track the current member and ensure WriteEndMember precedes any re-open.","typeGuard":null,"tryCatchPattern":"try { writer.WriteStartObject(rootType); /* ... */ }\ncatch (XamlDuplicateMemberException ex) {\n    // log ex.MemberName / ex.Message, then fix the source XAML that duplicated the member.\n}","preventionTips":["Author scalar properties with one assignment only (attribute XOR property element, not both).","When driving the writer programmatically, always pair WriteStartMember with WriteEndMember.","Use a XAML linter/style check to catch duplicate property elements at build time."],"tags":["xaml","duplicate-member","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}