dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(oldNamespace))
Error message
ArgumentNullException(nameof(oldNamespace))
What it means
The XmlnsCompatibleWithAttribute constructor throws ArgumentNullException when oldNamespace is null. This attribute declares that an old XML namespace is subsumed by a new one; the old namespace identifier is the core datum, so null is rejected at construction.
Solutions
- Pass the full old namespace URI string, e.g. "http://schemas.example.com/2006/xaml".
- Validate the config/source string for null before constructing the attribute.
- Use string constants from a shared namespace definitions file to avoid typos/nulls.
- Catch ArgumentNullException if attribute inputs are untrusted metadata.
Example fix
// before var attr = new XmlnsCompatibleWithAttribute(GetOldNs(), newNs); // GetOldNs() null // after var oldNs = GetOldNs() ?? "http://schemas.example.com/2006/xaml"; var attr = new XmlnsCompatibleWithAttribute(oldNs, newNs);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(oldNamespace)) throw new ArgumentException("oldNamespace is required.");
var attr = new XmlnsCompatibleWithAttribute(oldNamespace, newNamespace); Try / catch
try { attr = new XmlnsCompatibleWithAttribute(oldNs, newNs); }
catch (ArgumentNullException ex) { log.Error($"Bad xmlns compatibility metadata: {ex.ParamName}"); attr = null; } Prevention
- Keep namespace URIs as named constants in a shared file.
- Validate migration/config tables for null entries before emitting attributes.
When it happens
Trigger: Executing new XmlnsCompatibleWithAttribute(null, "http://new-namespace") from assembly attribute metadata or reflection-driven code.
Common situations: Generating compatibility attributes from config where the old-namespace entry is missing; merging assembly info files and dropping the old namespace value.
Related errors
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(prefix))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9d69945352433df0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs:31
///
/// "http://schemas.example.com/2003/mynamespace"
///
/// is changed to
///
/// "http://schemas.example.com/2005/mynamespace"
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
[TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public sealed class XmlnsCompatibleWithAttribute : Attribute
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="oldNamespace">old Xml namespce</param>
/// <param name="newNamespace">new xml namespace</param>
public XmlnsCompatibleWithAttribute(string oldNamespace, string newNamespace)
{
OldNamespace = oldNamespace ?? throw new ArgumentNullException(nameof(oldNamespace));
NewNamespace = newNamespace ?? throw new ArgumentNullException(nameof(newNamespace));
}
/// <summary>
/// Old Xml Namespace
/// </summary>
public string OldNamespace { get; }
/// <summary>
/// New Xml Namespace
/// </summary>
public string NewNamespace { get; }
}
}
View on GitHub (pinned to 81131a70a4)