dotnet/wpf · error · ArgumentNullException
throw new ArgumentNullException(nameof(xmlNamespace));
Error message
throw new ArgumentNullException(nameof(xmlNamespace));
What it means
The NamespaceMapEntry constructor validates its three string parameters and throws ArgumentNullException when xmlNamespace is null. A namespace map entry associates an XML namespace with an assembly and CLR namespace for XAML type resolution; the xmlNamespace is the primary key, so null is rejected.
Solutions
- Pass the XML namespace URI string as the first constructor argument
- Read the namespace from the parsed NamespaceDeclaration rather than assuming it
- Fail fast at the caller: check string.IsNullOrEmpty(xmlNamespace) before constructing the map entry
Example fix
// before
var map = new NamespaceMapEntry(nsUri, asm, clrNs); // nsUri may be null
// after
if (nsUri == null)
throw new InvalidOperationException("xmlns declaration missing for prefix");
var map = new NamespaceMapEntry(nsUri, asm, clrNs); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(xmlNamespace))
throw new ArgumentException("xmlNamespace must be a non-empty URI");
var entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace); Type guard
bool CanBuildNamespaceMap(string xmlNamespace, string asm, string clrNs) =>
!string.IsNullOrEmpty(xmlNamespace) && !string.IsNullOrEmpty(asm) && !string.IsNullOrEmpty(clrNs); Try / catch
try
{
var entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);
}
catch (ArgumentNullException ex)
{
log.LogError(ex, "Namespace map entry incomplete: {Param} is null", ex.ParamName);
} Prevention
- Verify xmlns declarations exist before creating map entries
- Build map entries from parsed NamespaceDeclaration data, not raw strings
- Validate all three arguments together in a helper before constructing
When it happens
Trigger: Constructing new NamespaceMapEntry(null, assemblyName, clrNamespace) — typically when the namespace URI came from an unparsed xmlns attribute or a lookup that returned null.
Common situations: Building custom XAML schema contexts in designers; programmatically registering namespace maps where xmlns declarations were missing from source XAML.
Related errors
- throw new ArgumentNullException(nameof(assemblyName));
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(assemblyPath))
- ArgumentNullException(nameof(clrNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/efe7ef9663b1f880.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:4230
#region Constructors
///<summary>
/// NamespaceMapEntry default constructor
///</summary>
public NamespaceMapEntry()
{
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="xmlNamespace">The XML NamespaceURi</param>
/// <param name="assemblyName">Assembly to use when resolving a Tag</param>
/// <param name="clrNamespace">Namespace within the assembly</param>
public NamespaceMapEntry(string xmlNamespace,string assemblyName,string clrNamespace)
{
if (xmlNamespace == null)
throw new ArgumentNullException(nameof(xmlNamespace));
if (assemblyName == null)
throw new ArgumentNullException(nameof(assemblyName));
if (clrNamespace == null)
throw new ArgumentNullException(nameof(clrNamespace));
_xmlNamespace = xmlNamespace;
_assemblyName = assemblyName;
_clrNamespace = clrNamespace;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="xmlNamespace">The XML NamespaceURi</param>
/// <param name="assemblyName">Assembly to use when resolving a Tag</param>
/// <param name="clrNamespace">Namespace within the assembly</param>View on GitHub (pinned to 81131a70a4)