dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(newNamespace))
Error message
ArgumentNullException(nameof(newNamespace))
What it means
The XmlnsCompatibleWithAttribute constructor throws ArgumentNullException when newNamespace is null. The new (compatible) namespace URI is required so the XAML infrastructure can map old namespace usage forward; null is rejected immediately.
Solutions
- Pass the full new namespace URI string.
- Validate the source value for null before constructing the attribute.
- Use shared namespace constants to keep old/new URIs consistent and non-null.
- Catch ArgumentNullException when consuming untrusted metadata.
Example fix
// before var attr = new XmlnsCompatibleWithAttribute(oldNs, GetNewNs()); // null // after var newNs = GetNewNs() ?? "http://schemas.example.com/2010/xaml"; var attr = new XmlnsCompatibleWithAttribute(oldNs, newNs);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(newNamespace)) throw new ArgumentException("newNamespace 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 generated attribute inputs for null before construction.
When it happens
Trigger: Executing new XmlnsCompatibleWithAttribute("http://old-namespace", null) from assembly metadata or generated code.
Common situations: Migration tooling that emits compatibility attributes but fails to supply the target namespace; config/translation tables missing the new-namespace entry.
Related errors
- ArgumentNullException(nameof(oldNamespace))
- 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/ed483f86a5cdb51c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs:32
/// "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)