dotnet/wpf · error · XamlXmlWriterException
XamlXmlWriterException(SR.Format(SR.XamlXmlWriterDuplicateMe…
Error message
XamlXmlWriterException(SR.Format(SR.XamlXmlWriterDuplicateMember, property.Name))
What it means
Within a single object element, each XAML member (property) may be written at most once. CheckMemberForUniqueness tracks written members per object frame and throws XamlXmlWriterException when WriteStartMember is called twice for the same property on the same object, which would produce invalid XML (duplicate attributes/elements).
Solutions
- Track members already written for the current object and skip duplicates
- Deduplicate the property list before the write loop (e.g. via Distinct on XamlMember)
- Fix node-stream transformation logic so each member is emitted exactly once per object
Example fix
// before
foreach (var m in members) { writer.WriteStartMember(m); WriteMemberValue(m); writer.WriteEndMember(); }
// after
foreach (var m in members.Distinct()) { writer.WriteStartMember(m); WriteMemberValue(m); writer.WriteEndMember(); } Defensive patterns
Strategy: validation
Validate before calling
var seen = new HashSet<XamlMember>(); if (!seen.Add(member)) return; // duplicate member for current object; skip
Try / catch
try { writer.WriteStartMember(member); }
catch (XamlXmlWriterException) { /* duplicate member; skip or fail with context */ } Prevention
- Deduplicate member lists before writing
- Don't write the same property via multiple paths (element and generated content)
- Assert one StartMember per member per object in your emitter
When it happens
Trigger: Calling WriteStartMember twice with the same XamlMember on the current object without an intervening WriteEndMember, e.g. writing a property via both a property element and again via its content/attachment path.
Common situations: Hand-built XAML node loops that iterate properties without deduplication; transform code that merges two node streams and emits the same property twice; wrappers that write a property plus a generated duplicate (e.g. both _Items and the typed property).
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- NotImplementedException(SR.MissingCaseXamlNodes)
- NotSupportedException(SR.MissingCaseXamlNodes)
- SR.Format(SR.TemplateNotCollected, "WriteValue")
- SR.Format(SR.XamlMarkupExtensionWriterDuplicateMember…
- SR.XamlFactoryInvalidXamlNode
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d73f5b8756dd5fee.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs:515
Frame objectFrame = namespaceScopes.Peek();
if (objectFrame.AllocatingNodeType != XamlNodeType.StartObject &&
objectFrame.AllocatingNodeType != XamlNodeType.GetObject)
{
Frame temp = namespaceScopes.Pop();
objectFrame = namespaceScopes.Peek();
namespaceScopes.Push(temp);
}
Debug.Assert(objectFrame.AllocatingNodeType == XamlNodeType.StartObject ||
objectFrame.AllocatingNodeType == XamlNodeType.GetObject);
if (objectFrame.Members is null)
{
objectFrame.Members = new XamlPropertySet();
}
else if (objectFrame.Members.Contains(property))
{
throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterDuplicateMember, property.Name));
}
objectFrame.Members.Add(property);
}
}
private void WriteDeferredNamespaces(XamlNodeType nodeType)
{
Frame frame = namespaceScopes.Peek();
if (frame.AllocatingNodeType != nodeType)
{
Frame temp = namespaceScopes.Pop();
frame = namespaceScopes.Peek();
Debug.Assert(frame.AllocatingNodeType == nodeType);
namespaceScopes.Push(temp);
}
var prefixMap = frame.GetSortedPrefixMap();View on GitHub (pinned to 81131a70a4)