dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(loaderType))
Error message
ArgumentNullException(nameof(loaderType))
What it means
The XamlDeferLoadAttribute(string,string) constructor throws ArgumentNullException when the loaderType string is null. This attribute records deferred-loading type names as strings for the XAML parser; a null loader name is meaningless and rejected at construction.
Solutions
- Pass a valid assembly-qualified or XAML-namespace type-name string for loaderType.
- Validate the config/source value for null before constructing the attribute.
- Use the (Type,Type) constructor overload with concrete types when available.
- Catch ArgumentNullException and log/skip invalid attribute metadata.
Example fix
// before
var attr = new XamlDeferLoadAttribute(GetSetting("loader"), "MyContent"); // setting missing
// after
var loader = GetSetting("loader") ?? "MyNs.MyDeferredLoader";
var attr = new XamlDeferLoadAttribute(loader, "MyContent"); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(loaderTypeName)) throw new ArgumentException("loaderType 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 so the compiler catches missing values.
- Validate configuration values before building attributes from them.
When it happens
Trigger: Executing new XamlDeferLoadAttribute(null, "SomeContentType") or new XamlDeferLoadAttribute(null, null).
Common situations: Building the attribute via reflection/config-driven code where the loader type name comes from a missing setting; hand-writing attribute metadata and leaving the loader argument empty.
Related errors
- ArgumentNullException(nameof(contentType))
- 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/c142cd0b56f1ed4d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs:21
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)