{"record":{"id":"a0f30b901f25b20c","repo":"dotnet/wpf","slug":"sr-nulluri","errorCode":null,"errorMessage":"SR.NullUri","messagePattern":"SR\\.NullUri","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":782,"sourceCode":"        private void CheckKnownNamespaces(IDictionary<Uri, IList<Uri>> knownNamespaces)\n        {\n            if (knownNamespaces == null)\n                return;\n\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));","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L764-L800","documentation":"CheckKnownNamespaces throws ArgumentException (SR.NullUri) when the knownNamespaces dictionary passed to XmlStreamStore's constructor contains a null key (a null namespace Uri). Known namespaces must all be valid, distinct Uris.","triggerScenarios":"new XmlStreamStore(stream, knownNamespaces) where dictionary keys include null (e.g., built from data where a namespace lookup returned null); checked during CheckKnownNamespaces from LoadStream.","commonSituations":"Building the namespace map from configuration where a missing entry became null; deserializing a namespace list with a null element; copy-pasting a sample dictionary with placeholder null keys.","solutions":["Remove null keys from the knownNamespaces dictionary before constructing the store.","Substitute a valid namespace Uri for the null entry, or drop the entry entirely.","Guard the input: if (knownNamespaces.Keys.Any(k => k == null)) throw/report before constructing."],"exampleFix":"// before\nvar known = new Dictionary<Uri, IList<Uri>> { { null, null } };\nvar store = new XmlStreamStore(stream, known);\n\n// after\nvar known = new Dictionary<Uri, IList<Uri>>();\nknown[new Uri(\"http://schemas.microsoft.com/windows/annotations/2003/11/base\")] = null;\nvar store = new XmlStreamStore(stream, known);","handlingStrategy":"validation","validationCode":"if (knownNamespaces == null || knownNamespaces.Keys.Any(k => k == null)) throw new ArgumentException(\"knownNamespaces contains a null Uri\");","typeGuard":"bool HasNullKeys(Dictionary<Uri, IList<Uri>> map) => map == null || map.Keys.Any(k => k == null);","tryCatchPattern":"try { var store = new XmlStreamStore(stream, knownNamespaces); }\ncatch (ArgumentException ex) when (ex.ParamName == \"knownNamespaces\") { /* sanitize and retry */ }","preventionTips":["Build knownNamespaces dictionaries only from validated, non-null Uri sources.","Skip null entries defensively when populating the dictionary.","Unit-test store construction with your real configuration data."],"tags":["null-reference","namespace","wpf","argument-exception"],"backgroundTag":"null-argument","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"}