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

  1. Deduplicate each compatible list (Distinct()) and against already-collected namespaces before constructing the store.
  2. Keep a running HashSet<Uri> of all namespaces while building the map and skip any Uri already present.
  3. 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

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


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)