unoplatform/uno · error · XamlDuplicateMemberException
Member '{0}' is already written to current type '{1}'
Error message
Member '{0}' is already written to current type '{1}' What it means
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.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:239
XamlObjectWriter source;
XamlSchemaContext sctx;
INameScope name_scope;
List<NameFixupRequired> pending_name_references = new List<NameFixupRequired> ();
AmbientProvider ambient_provider = new AmbientProvider ();
public INameScope NameScope {
get { return name_scope; }
}
public object Result { get; set; }
protected override void OnWriteStartObject ()
{
var state = object_states.Pop ();
if (object_states.Count > 0) {
var pstate = object_states.Peek ();
if (CurrentMemberState.Value != null)
throw new XamlDuplicateMemberException (String.Format (CultureInfo.InvariantCulture, "Member '{0}' is already written to current type '{1}'", CurrentMember, pstate.Type));
} else {
var obj = source.Settings.RootObjectInstance;
if (obj != null) {
if (state.Type.UnderlyingType != null && !state.Type.UnderlyingType.IsAssignableFrom (obj.GetType ()))
throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "RootObjectInstance type '{0}' is not assignable to '{1}'", obj.GetType (), state.Type));
state.Value = obj;
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);
}
View on GitHub (pinned to 0418340488)
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.
Example fix
<!-- before --> <Button> <Button.Content>A</Button.Content> <Button.Content>B</Button.Content> </Button> <!-- after --> <Button Content="A" />
Defensive patterns
Strategy: validation
Validate before calling
// Validate XAML does not repeat the same property element before writing. // If building the node stream programmatically, track the current member and ensure WriteEndMember precedes any re-open.
Try / catch
try { writer.WriteStartObject(rootType); /* ... */ }
catch (XamlDuplicateMemberException ex) {
// log ex.MemberName / ex.Message, then fix the source XAML that duplicated the member.
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- RootObjectInstance type '{0}' is not assignable to '{1}'
- The value for '{0}' property is null
- 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/82e9bdecb82fd482.
Report an issue: GitHub.