dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(contentType))
Error message
ArgumentNullException(nameof(contentType))
What it means
The XamlDeferLoadAttribute(string,string) constructor throws ArgumentNullException when the contentType string is null. Alongside the loader type name, the content type name is required metadata for deferred XAML loading, so null is rejected immediately.
Solutions
- Pass a valid type-name string for contentType.
- Validate the source value for null before constructing.
- Use the (Type,Type) constructor overload with concrete types.
- Catch ArgumentNullException around attribute construction when inputs are untrusted.
Example fix
// before
var attr = new XamlDeferLoadAttribute("MyLoader", GetSetting("content")); // null
// after
var content = GetSetting("content") ?? "MyNs.MyContent";
var attr = new XamlDeferLoadAttribute("MyLoader", content); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(contentTypeName)) throw new ArgumentException("contentType is required.");
var attr = new XamlDeferLoadAttribute(loaderTypeName, contentTypeName); Try / catch
try { attr = new XamlDeferLoadAttribute(loader, content); }
catch (ArgumentNullException ex) { log.Error($"Bad defer-load metadata: {ex.ParamName}"); attr = null; } Prevention
- Prefer the (Type, Type) constructor overload with concrete types.
- Validate all attribute inputs sourced from config before construction.
When it happens
Trigger: Executing new XamlDeferLoadAttribute("MyLoader", null) or new XamlDeferLoadAttribute(null, null).
Common situations: Config-driven attribute construction where the content-type setting is absent; hand-authoring attribute metadata with a placeholder never filled in.
Related errors
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(oldNamespace))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(prefix))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5747df3a6d0d7bf0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs:22
namespace System.Windows.Markup
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class XamlDeferLoadAttribute : Attribute
{
public XamlDeferLoadAttribute(Type loaderType, Type contentType)
{
ArgumentNullException.ThrowIfNull(loaderType);
ArgumentNullException.ThrowIfNull(contentType);
LoaderTypeName = loaderType.AssemblyQualifiedName!;
ContentTypeName = contentType.AssemblyQualifiedName!;
LoaderType = loaderType;
ContentType = contentType;
}
public XamlDeferLoadAttribute(string loaderType, string contentType)
{
LoaderTypeName = loaderType ?? throw new ArgumentNullException(nameof(loaderType));
ContentTypeName = contentType ?? throw new ArgumentNullException(nameof(contentType));
}
public string LoaderTypeName { get; }
public string ContentTypeName { get; }
public Type? LoaderType { get; private set; }
public Type? ContentType { get; private set; }
}
}
View on GitHub (pinned to 81131a70a4)