{"record":{"id":"89b40c32e19e9413","repo":"dotnet/wpf","slug":"sr-format-sr-invalidnamespace-xmlnamespace","errorCode":null,"errorMessage":"SR.Format(SR.InvalidNamespace, xmlNamespace)","messagePattern":"SR\\.Format\\(SR\\.InvalidNamespace, xmlNamespace\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":879,"sourceCode":"            return reader;\n        }\n\n        /// <summary>\n        /// A callback for XmlCompatibilityReader\n        /// </summary>\n        /// <param name=\"xmlNamespace\">inquired namespace</param>\n        /// <param name=\"newXmlNamespace\">the newer subsumming namespace</param>\n        /// <returns>true if the namespace is known, false if not</returns>\n        /// <remarks>This API always returns false because all known namespaces are registered\n        /// before loading the Xml. It stores the namespace as ignored.</remarks>\n        private bool IsXmlNamespaceSupported(string xmlNamespace, out string newXmlNamespace)\n        {\n            //store the namespace if needed\n            if (!String.IsNullOrEmpty(xmlNamespace))\n            {\n                if (!Uri.IsWellFormedUriString(xmlNamespace, UriKind.RelativeOrAbsolute))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidNamespace, xmlNamespace), nameof(xmlNamespace));\n                }\n                Uri namespaceUri = new Uri(xmlNamespace, UriKind.RelativeOrAbsolute);\n                if (!_ignoredNamespaces.Contains(namespaceUri))\n                    _ignoredNamespaces.Add(namespaceUri);\n            }\n\n            newXmlNamespace = null;\n            return false;\n        }\n\n\n\n        /// <summary>\n        ///     Selects the annotation XmlElement from the current document\n        ///     with the given id.\n        /// </summary>\n        /// <param name=\"id\">the id to query for in the XmlDocument</param>\n        /// <returns>the XmlElement representing the annotation with the given id</returns>","sourceCodeStart":861,"sourceCodeEnd":897,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L861-L897","documentation":"IsXmlNamespaceSupported (AddIgnoredNamespace path) throws ArgumentException (SR.InvalidNamespace) when the xmlNamespace string supplied is not empty but is not a well-formed absolute or relative Uri. Ignored namespaces must be valid Uri strings.","triggerScenarios":"Calling XmlStreamStore.AddIgnoredNamespace(xmlNamespace) with a non-empty string that fails Uri.IsWellFormedUriString, e.g., containing spaces or illegal characters like \"my namespace\" or \"<test>\".","commonSituations":"Passing a human-readable label instead of a namespace Uri; config values with unencoded spaces; typos in namespace strings; concatenating strings to build a namespace and forgetting Uri.EscapeDataString.","solutions":["Pass a proper namespace Uri string, e.g., \"http://schemas.example.com/my-annotations\".","Uri-escape invalid characters before calling (Uri.EscapeDataString for components).","Pre-check with Uri.IsWellFormedUriString(ns, UriKind.RelativeOrAbsolute) and skip or fix invalid values.","If you intend to ignore nothing, call nothing - empty/null strings are accepted as no-ops."],"exampleFix":"// before\nstore.AddIgnoredNamespace(\"my custom namespace\");\n\n// after\nstore.AddIgnoredNamespace(\"http://schemas.example.com/my-annotations\");","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(ns) && !Uri.IsWellFormedUriString(ns, UriKind.RelativeOrAbsolute))\n    throw new ArgumentException($\"Invalid namespace: {ns}\");","typeGuard":"bool IsValidNamespace(string ns) => string.IsNullOrEmpty(ns) || Uri.IsWellFormedUriString(ns, UriKind.RelativeOrAbsolute);","tryCatchPattern":"try { store.AddIgnoredNamespace(ns); }\ncatch (ArgumentException ex) when (ex.ParamName == \"xmlNamespace\") { log.Warn($\"Skipping invalid ignored namespace: {ns}\"); }","preventionTips":["Always pass full namespace Uri strings, not display names.","Validate namespace strings with Uri.IsWellFormedUriString before calling AddIgnoredNamespace.","Escape dynamic components with Uri.EscapeDataString instead of string concatenation."],"tags":["uri","namespace","wpf","argument-exception"],"backgroundTag":"invalid-url-format","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"}