dotnet/wpf · error · ArgumentException

SR.DuplicatedUri

Error message

SR.DuplicatedUri

What it means

CheckKnownNamespaces throws ArgumentException (SR.DuplicatedUri) when the same namespace Uri appears more than once as a key in the knownNamespaces dictionary. Each known namespace must be unique within the map used by the store.

Solutions

  1. Deduplicate keys before construction: use a HashSet<Uri> or Dictionary key uniqueness to ensure each namespace appears once.
  2. Use UriComparer/ordinal comparison while building the map to collapse equivalent Uris.
  3. Skip already-present namespaces when populating the dictionary instead of overwriting.

Example fix

// before
known[uri] = list1;
known[uri] = list2; // duplicate key scenario feeding duplicates downstream

// after
if (!known.ContainsKey(uri))
    known[uri] = list1;
Defensive patterns

Strategy: validation

Validate before calling

var seen = new HashSet<Uri>();
foreach (var key in knownNamespaces.Keys)
    if (!seen.Add(key)) throw new ArgumentException($"Duplicate known namespace: {key}");

Try / catch

try { var store = new XmlStreamStore(stream, knownNamespaces); }
catch (ArgumentException ex) when (ex.ParamName == "knownNamespaces") { /* deduplicate and retry */ }

Prevention

When it happens

Trigger: new XmlStreamStore(stream, knownNamespaces) where two keys in the dictionary are equal Uris (or the same Uri object inserted twice); Uris are compared after normalization, so syntactic duplicates are caught.

Common situations: Merging namespace lists from multiple configuration sources with overlapping namespaces; adding the same well-known namespace (e.g., the base annotations namespace) repeatedly; case/scheme variants that resolve to the same Uri.

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/aa74036e4ccc02b7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs:786

            IList<Uri> allNamespaces = new List<Uri>();

            //add AnnotationFramework namespaces
            foreach (Uri name in _predefinedNamespaces.Keys)
            {
                allNamespaces.Add(name);
            }

            //add external namespaces
            foreach (Uri knownNamespace in knownNamespaces.Keys)
            {
                if (knownNamespace == null)
                {
                    throw new ArgumentException(SR.NullUri, nameof(knownNamespaces));
                }
                if (allNamespaces.Contains(knownNamespace))
                {
                    throw new ArgumentException(SR.DuplicatedUri, nameof(knownNamespaces));
                }
                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))
                        {

View on GitHub (pinned to 81131a70a4)