dotnet/wpf · error · ArgumentException
SR.Format(SR.InvalidNamespace, xmlNamespace)
Error message
SR.Format(SR.InvalidNamespace, xmlNamespace)
What it means
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.
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.
Example fix
// before
store.AddIgnoredNamespace("my custom namespace");
// after
store.AddIgnoredNamespace("http://schemas.example.com/my-annotations"); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(ns) && !Uri.IsWellFormedUriString(ns, UriKind.RelativeOrAbsolute))
throw new ArgumentException($"Invalid namespace: {ns}"); Type guard
bool IsValidNamespace(string ns) => string.IsNullOrEmpty(ns) || Uri.IsWellFormedUriString(ns, UriKind.RelativeOrAbsolute);
Try / catch
try { store.AddIgnoredNamespace(ns); }
catch (ArgumentException ex) when (ex.ParamName == "xmlNamespace") { log.Warn($"Skipping invalid ignored namespace: {ns}"); } Prevention
- 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.
When it happens
Trigger: 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>".
Common situations: 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.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- SR.DuplicatedCompatibleUri
- SR.DuplicatedUri
- SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
- SR.NullUri
- ArgumentNullException(nameof(newNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/89b40c32e19e9413.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs:879
return reader;
}
/// <summary>
/// A callback for XmlCompatibilityReader
/// </summary>
/// <param name="xmlNamespace">inquired namespace</param>
/// <param name="newXmlNamespace">the newer subsumming namespace</param>
/// <returns>true if the namespace is known, false if not</returns>
/// <remarks>This API always returns false because all known namespaces are registered
/// before loading the Xml. It stores the namespace as ignored.</remarks>
private bool IsXmlNamespaceSupported(string xmlNamespace, out string newXmlNamespace)
{
//store the namespace if needed
if (!String.IsNullOrEmpty(xmlNamespace))
{
if (!Uri.IsWellFormedUriString(xmlNamespace, UriKind.RelativeOrAbsolute))
{
throw new ArgumentException(SR.Format(SR.InvalidNamespace, xmlNamespace), nameof(xmlNamespace));
}
Uri namespaceUri = new Uri(xmlNamespace, UriKind.RelativeOrAbsolute);
if (!_ignoredNamespaces.Contains(namespaceUri))
_ignoredNamespaces.Add(namespaceUri);
}
newXmlNamespace = null;
return false;
}
/// <summary>
/// Selects the annotation XmlElement from the current document
/// with the given id.
/// </summary>
/// <param name="id">the id to query for in the XmlDocument</param>
/// <returns>the XmlElement representing the annotation with the given id</returns>View on GitHub (pinned to 81131a70a4)