dotnet/wpf · error · ArgumentNullException
throw new ArgumentNullException(nameof(value));
Error message
throw new ArgumentNullException(nameof(value));
What it means
The XmlNamespace property setter on XamlTypeMapper's mapping entry type rejects null values with ArgumentNullException. The setter is write-once: it only assigns the backing field when it is still null, but null values are rejected outright to keep the namespace mapping well-formed.
Solutions
- Assign a non-null namespace string (e.g. 'http://schemas.microsoft.com/winfx/2006/xaml/presentation')
- Guard with string.IsNullOrEmpty before assignment
- If clearing the mapping is intended, replace the whole mapping object instead of nulling a property
Example fix
// before entry.XmlNamespace = config.XmlNamespace; // may be null // after if (config.XmlNamespace != null) entry.XmlNamespace = config.XmlNamespace;
Defensive patterns
Strategy: validation
Validate before calling
if (ns != null) entry.XmlNamespace = ns;
Type guard
static bool IsValidNamespace(string s) => !string.IsNullOrEmpty(s);
Try / catch
try { entry.XmlNamespace = value; }
catch (ArgumentNullException ex) { Log.Warn("XmlNamespace cannot be null: " + ex.Message); } Prevention
- Check config/deserialized namespace strings for null before assignment
- Use string.Empty for default namespaces rather than null
When it happens
Trigger: Assigning null to the XmlNamespace property of a XamlTypeMapper mapping entry (e.g. mapper.XmlNamespace = someString) where someString is null.
Common situations: Deserialization or config parsing that produced a null namespace string; test code probing the setter's behavior.
Related errors
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(assemblyPath))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(localName))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e1b974d904fe84c8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:4274
_assemblyPath = assemblyPath;
}
#endregion Constructors
#region Properties
/// <summary>
/// Xml namespace specified in the constructor
/// </summary>
public string XmlNamespace
{
get { return _xmlNamespace; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (_xmlNamespace == null)
{
_xmlNamespace = value;
}
}
}
/// <summary>
/// AssemblyName specified in the constructor
/// </summary>
public string AssemblyName
{
get { return _assemblyName; }
set
{
if (value == null)
{View on GitHub (pinned to 81131a70a4)