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

  1. Remove the duplicate property element/assignment in the XAML so the member is set exactly once.
  2. If writing the object graph programmatically, call WriteEndMember() before starting the same member again.
  3. 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

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


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