dotnet/wpf · error · ArgumentNullException
throw new ArgumentNullException(nameof(assemblyName));
Error message
throw new ArgumentNullException(nameof(assemblyName));
What it means
The NamespaceMapEntry constructor throws ArgumentNullException when assemblyName is null. The assembly name is required to locate the CLR types that back the mapped XML namespace, so a null value makes the entry unusable.
Solutions
- Pass the assembly's simple name string as the second constructor argument
- Derive the name via Assembly.GetName().Name when only an Assembly object is available
- Validate the mapping instruction/config entry contains an Assembly value before constructing
Example fix
// before var map = new NamespaceMapEntry(nsUri, mappingInfo.Assembly, clrNs); // may be null // after string asmName = mappingInfo.Assembly ?? typeof(KnownType).Assembly.GetName().Name; var map = new NamespaceMapEntry(nsUri, asmName, clrNs);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(assemblyName))
assemblyName = typeof(FrameworkElement).Assembly.GetName().Name; // or explicit failure
var entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace); Type guard
bool HasAssemblyName(string assemblyName) => !string.IsNullOrEmpty(assemblyName);
Try / catch
try
{
var entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);
}
catch (ArgumentNullException ex) when (ex.ParamName == "assemblyName")
{
log.LogError(ex, "Mapping for {Ns} lacks an Assembly attribute", xmlNamespace);
} Prevention
- Ensure <?Mapping ...?> or config entries always include Assembly=
- Use Assembly.GetName().Name instead of hand-written names
- Check for assembly renames when migrating mapping metadata
When it happens
Trigger: Constructing new NamespaceMapEntry(xmlNamespace, null, clrNamespace) — often when the assembly name is derived from a mapping instruction or config entry that was missing.
Common situations: Designer/tooling code registering namespace maps from <?Mapping ...?> data with missing Assembly= attributes; assembly renames leaving old mapping metadata pointing at nothing.
Related errors
- throw new ArgumentNullException(nameof(xmlNamespace));
- 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/0d835500e8f9c5dc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:4233
/// 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>
/// <param name="assemblyPath">Path to use when loading assembly. This may be null.</param>
internal NamespaceMapEntry(
string xmlNamespace,View on GitHub (pinned to 81131a70a4)