dotnet/wpf · error · ArgumentNullException
type
Error message
type
What it means
The public XamlTypeInvoker(XamlType type) constructor requires a non-null XamlType; passing null throws ArgumentNullException with parameter name 'type'. An invoker cannot operate without its owning XamlType.
Solutions
- Null-check the XamlType before constructing; handle the unresolved-type case explicitly.
- Use the type's existing invoker: XamlType.Invoker already returns a correctly constructed XamlTypeInvoker.
- Use XamlTypeInvoker.UnknownInvoker for unknown-type scenarios instead of constructing an invoker.
Example fix
// before
var invoker = new XamlTypeInvoker(schemaContext.GetXamlType(clrType)); // throws if null
// after
var xamlType = schemaContext.GetXamlType(clrType);
if (xamlType is null) { /* type not mapped */ return; }
var invoker = xamlType.Invoker; Defensive patterns
Strategy: type-guard
Validate before calling
if (xamlType is null) return; // type not resolvable in schema context
Type guard
static bool TryGetInvoker(XamlType? t, out XamlTypeInvoker? invoker) { invoker = t?.Invoker; return invoker is not null; } Try / catch
try { var invoker = new XamlTypeInvoker(xamlType); }
catch (ArgumentNullException ex) when (ex.ParamName == "type") { /* type lookup failed */ } Prevention
- Prefer xamlType.Invoker over manual construction
- Check GetXamlType results for null before using them
- Use XamlTypeInvoker.UnknownInvoker for unresolved types
When it happens
Trigger: Calling `new XamlTypeInvoker(null)`, typically when a preceding lookup like schemaContext.GetXamlType(clrType) or XamlType returned null and the result flows into the constructor.
Common situations: Custom type mapping/extension code constructing invokers for types resolved at runtime; assemblies removed or renamed so the type lookup silently returns null.
Related errors
- member
- ArgumentNullException
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/698bd5f314695a4a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs:31
public class XamlTypeInvoker
{
private static XamlTypeInvoker s_Unknown;
private Dictionary<XamlType, MethodInfo> _addMethods;
internal MethodInfo EnumeratorMethod { get; set; }
private XamlType _xamlType;
private Action<object> _constructorDelegate;
private ThreeValuedBool _isPublic;
protected XamlTypeInvoker()
{
}
public XamlTypeInvoker(XamlType type)
{
_xamlType = type ?? throw new ArgumentNullException(nameof(type));
}
public static XamlTypeInvoker UnknownInvoker
{
get
{
if (s_Unknown is null)
{
s_Unknown = new XamlTypeInvoker();
}
return s_Unknown;
}
}
public EventHandler<XamlSetMarkupExtensionEventArgs> SetMarkupExtensionHandler
{
get { return _xamlType?.SetMarkupExtensionHandler; }View on GitHub (pinned to 81131a70a4)