{"record":{"id":"aa74036e4ccc02b7","repo":"dotnet/wpf","slug":"sr-duplicateduri","errorCode":null,"errorMessage":"SR.DuplicatedUri","messagePattern":"SR\\.DuplicatedUri","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":786,"sourceCode":"\n            IList<Uri> allNamespaces = new List<Uri>();\n\n            //add AnnotationFramework namespaces\n            foreach (Uri name in _predefinedNamespaces.Keys)\n            {\n                allNamespaces.Add(name);\n            }\n\n            //add external namespaces\n            foreach (Uri knownNamespace in knownNamespaces.Keys)\n            {\n                if (knownNamespace == null)\n                {\n                    throw new ArgumentException(SR.NullUri, nameof(knownNamespaces));\n                }\n                if (allNamespaces.Contains(knownNamespace))\n                {\n                    throw new ArgumentException(SR.DuplicatedUri, nameof(knownNamespaces));\n                }\n                allNamespaces.Add(knownNamespace);\n            }\n\n            // check compatible namespaces\n            foreach (KeyValuePair<Uri, IList<Uri>> item in knownNamespaces)\n            {\n                if (item.Value != null)\n                {\n                    foreach (Uri name in item.Value)\n                    {\n                        if (name == null)\n                        {\n                            throw new ArgumentException(SR.NullUri, nameof(knownNamespaces));\n                        }\n\n                        if (allNamespaces.Contains(name))\n                        {","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L768-L804","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Deduplicate keys before construction: use a HashSet<Uri> or Dictionary key uniqueness to ensure each namespace appears once.","Use UriComparer/ordinal comparison while building the map to collapse equivalent Uris.","Skip already-present namespaces when populating the dictionary instead of overwriting."],"exampleFix":"// before\nknown[uri] = list1;\nknown[uri] = list2; // duplicate key scenario feeding duplicates downstream\n\n// after\nif (!known.ContainsKey(uri))\n    known[uri] = list1;","handlingStrategy":"validation","validationCode":"var seen = new HashSet<Uri>();\nforeach (var key in knownNamespaces.Keys)\n    if (!seen.Add(key)) throw new ArgumentException($\"Duplicate known namespace: {key}\");","typeGuard":null,"tryCatchPattern":"try { var store = new XmlStreamStore(stream, knownNamespaces); }\ncatch (ArgumentException ex) when (ex.ParamName == \"knownNamespaces\") { /* deduplicate and retry */ }","preventionTips":["Use a Dictionary/HashSet so key uniqueness is enforced structurally.","Deduplicate merged namespace lists from multiple config sources.","Normalize Uri casing/scheme before insertion to avoid near-duplicates."],"tags":["namespace","duplicate","wpf","argument-exception"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}