dotnet/wpf · error · ArgumentException
SR.NullUri
Error message
SR.NullUri
What it means
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.
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.
Example fix
// before
var known = new Dictionary<Uri, IList<Uri>> { { null, null } };
var store = new XmlStreamStore(stream, known);
// after
var known = new Dictionary<Uri, IList<Uri>>();
known[new Uri("http://schemas.microsoft.com/windows/annotations/2003/11/base")] = null;
var store = new XmlStreamStore(stream, known); Defensive patterns
Strategy: validation
Validate before calling
if (knownNamespaces == null || knownNamespaces.Keys.Any(k => k == null)) throw new ArgumentException("knownNamespaces contains a null Uri"); Type guard
bool HasNullKeys(Dictionary<Uri, IList<Uri>> map) => map == null || map.Keys.Any(k => k == null);
Try / catch
try { var store = new XmlStreamStore(stream, knownNamespaces); }
catch (ArgumentException ex) when (ex.ParamName == "knownNamespaces") { /* sanitize and retry */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SR.DuplicatedCompatibleUri
- SR.DuplicatedUri
- SR.Format(SR.InvalidNamespace, xmlNamespace)
- SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
- anchorLocator.Parts
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a0f30b901f25b20c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs:782
private void CheckKnownNamespaces(IDictionary<Uri, IList<Uri>> knownNamespaces)
{
if (knownNamespaces == null)
return;
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));View on GitHub (pinned to 81131a70a4)