unoplatform/uno · error · XamlDuplicateMemberException

Property '{0}' is already set to this '{1}' object

Error message

Property '{0}' is already set to this '{1}' object

What it means

WriteStartMember throws XamlDuplicateMemberException ('Property {0} is already set to this {1} object') when the same XamlMember is written twice within a single object scope. The writer tracks WrittenProperties per object state and rejects a second occurrence because XAML semantics do not allow setting the same property twice on one object (except PositionalParameters, which sets AcceptMultipleValues).

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlWriterInternalBase.cs:195

			manager.Value ();

			OnWriteValue (value);
		}
		
		public void WriteStartMember (XamlMember property)
		{
			if (property == null)
				throw new ArgumentNullException ("property");

			manager.StartMember ();
			if (property == XamlLanguage.PositionalParameters)
				// this is an exception that indicates the state manager to accept more than values within this member.
				manager.AcceptMultipleValues = true;

			var state = object_states.Peek ();
			var wpl = state.WrittenProperties;
			if (wpl.Any (wp => wp.Member == property))
				throw new XamlDuplicateMemberException (String.Format (CultureInfo.InvariantCulture, "Property '{0}' is already set to this '{1}' object", property, object_states.Peek ().Type));
			wpl.Add (new MemberAndValue (property));
			if (property == XamlLanguage.PositionalParameters)
				state.PositionalParameterIndex = 0;

			OnWriteStartMember (property);
		}
		
		public void WriteEndObject ()
		{
			manager.EndObject (object_states.Count > 1);

			OnWriteEndObject ();

			object_states.Pop ();
		}

		public void WriteEndMember ()
		{

View on GitHub (pinned to 0418340488)

Solutions

  1. Inspect the XAML for the property named in the message and remove the duplicate declaration on that element.
  2. If generating XAML programmatically, track which members have been written per object and skip duplicates.
  3. For collections that legitimately hold multiple values, ensure they are nested under the collection/add-member pattern rather than re-declaring the property.
  4. If using a transformer pipeline, verify it does not duplicate StartMember nodes.

Example fix

<!-- before -->
<Button Content="A" Content="B" />

<!-- after -->
<Button Content="A" />
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check: is this member already written in the current scope?
var seen = new HashSet<XamlMember>();
// before each WriteStartMember: if (!seen.Add(member)) skip or throw your own diagnostic;

Try / catch

try { writer.WriteStartMember(member); }
catch (XamlDuplicateMemberException ex) {
    // log the offending member + owning type from ex.Message, then fix source XAML
}

Prevention

When it happens

Trigger: XAML that sets the same attribute twice (e.g. <Button Content="A" Content="B"/>), or programmatic writer calls that emit the same StartMember twice before EndObject. PositionalParameters is the only built-in member that may repeat.

Common situations: Malformed XAML with duplicate attributes; merge/conflict in generated XAML producing duplicate properties; custom writers or transformers that accidentally duplicate a member node; style/template merging that double-sets a setter.

Related errors


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