dotnet/wpf · error · ArgumentException
SR.DuplicatedCompatibleUri
Error message
SR.DuplicatedCompatibleUri
What it means
CheckKnownNamespaces throws ArgumentException (SR.DuplicatedCompatibleUri) when a compatible namespace Uri appears more than once - either repeated within one compatible list or already registered as another known/compatible namespace. All namespaces collected must be distinct.
Solutions
- Deduplicate each compatible list (Distinct()) and against already-collected namespaces before constructing the store.
- Keep a running HashSet<Uri> of all namespaces while building the map and skip any Uri already present.
- Restructure configuration so each compatible namespace is declared exactly once.
Example fix
// before
known[a] = new List<Uri> { sharedUri };
known[b] = new List<Uri> { sharedUri }; // duplicate compatible Uri
// after
known[a] = new List<Uri> { sharedUri };
known[b] = new List<Uri>(); Defensive patterns
Strategy: validation
Validate before calling
var all = new HashSet<Uri>();
foreach (var kv in knownNamespaces) {
all.Add(kv.Key);
foreach (var u in kv.Value ?? (IList<Uri>)Array.Empty<Uri>())
if (!all.Add(u)) throw new ArgumentException($"Duplicate compatible namespace: {u}");
} Try / catch
try { var store = new XmlStreamStore(stream, knownNamespaces); }
catch (ArgumentException ex) when (ex.ParamName == "knownNamespaces") { /* deduplicate compatible lists and retry */ } Prevention
- Maintain a global HashSet<Uri> while building compatibility tables.
- Run Distinct() on every compatible-namespace list before constructing the store.
- Design config so each compatible namespace is declared in exactly one place.
When it happens
Trigger: new XmlStreamStore(stream, knownNamespaces) where the same Uri is listed as compatible with multiple known namespaces, or duplicated inside a single item.Value list.
Common situations: Merging compatibility tables where several namespaces declare the same compatibility target; copy-pasted lists; config files whose compatibility sections overlap.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.DuplicatedUri
- SR.Format(SR.InvalidNamespace, xmlNamespace)
- SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
- SR.InvalidStylusPointDescriptionDuplicatesFound
- SR.NullUri
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c0f2e7aa567d6e61.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs:805
}
allNamespaces.Add(knownNamespace);
}
// check compatible namespaces
foreach (KeyValuePair<Uri, IList<Uri>> item in knownNamespaces)
{
if (item.Value != null)
{
foreach (Uri name in item.Value)
{
if (name == null)
{
throw new ArgumentException(SR.NullUri, nameof(knownNamespaces));
}
if (allNamespaces.Contains(name))
{
throw new ArgumentException(SR.DuplicatedCompatibleUri, nameof(knownNamespaces));
}
allNamespaces.Add(name);
}//foreach
}//if
}//foreach
}
/// <summary>
/// Creates and initializes the XmlCompatibilityReader
/// </summary>
/// <param name="knownNamespaces">Dictionary of external known namespaces</param>
/// <returns>The XmlCompatibilityReader</returns>
private XmlCompatibilityReader SetupReader(IDictionary<Uri, IList<Uri>> knownNamespaces)
{
IList<string> supportedNamespaces = new List<string>();
//add AnnotationFramework namespaces
foreach (Uri name in _predefinedNamespaces.Keys)View on GitHub (pinned to 81131a70a4)