dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(arrayType))
Error message
ArgumentNullException(nameof(arrayType))
What it means
ArrayExtension's Type-taking constructor throws ArgumentNullException when the arrayType argument is null. The extension cannot represent an array without a type, so the library rejects null eagerly at construction time rather than failing later during ProvideValue. This is a standard argument-validation guard in System.Xaml markup extensions.
Solutions
- Pass a valid System.Type instance to the ArrayExtension(Type) constructor.
- If the Type comes from a dynamic lookup, check it for null before constructing the extension and handle the failed lookup separately.
- Use the parameterless ArrayExtension() constructor and set the Type property afterward if you intentionally defer type assignment.
Example fix
// before
var ext = new ArrayExtension(ResolveType("my:Widget[]")); // ResolveType may return null
// after
var t = ResolveType("my:Widget[]") ?? throw new InvalidOperationException("Array element type could not be resolved");
var ext = new ArrayExtension(t); Defensive patterns
Strategy: validation
Validate before calling
if (arrayType is null) throw new ArgumentException("arrayType must be a resolved Type", nameof(arrayType));
var ext = new ArrayExtension(arrayType); Type guard
bool IsValidArrayType(Type t) => t is not null;
Try / catch
try { var ext = new ArrayExtension(arrayType); }
catch (ArgumentNullException ex) when (ex.ParamName == "arrayType") { /* handle unresolved type */ } Prevention
- Never construct ArrayExtension(Type) from a lookup result without a null check.
- Prefer the parameterless constructor plus explicit Type assignment in staged construction.
- Centralize markup-extension construction in a factory that validates inputs.
When it happens
Trigger: Calling new ArrayExtension((Type)null) — directly or via reflection/activator from a XAML parser or serializer passing a null Type.
Common situations: Reflective construction of markup extensions where the Type was resolved dynamically (e.g. by assembly-qualified name lookup) and the lookup returned null; code generation tools emitting constructor calls with unresolved types.
Related errors
- ArgumentNullException(nameof(member))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(oldNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ca1a6964945782fb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ArrayExtension.cs:34
[ContentProperty("Items")]
[MarkupExtensionReturnType(typeof(Array))]
public class ArrayExtension : MarkupExtension
{
private readonly ArrayList _arrayList = new ArrayList();
/// <summary>
/// Constructor that takes no parameters. This creates an empty array.
/// </summary>
public ArrayExtension()
{
}
/// <summary>
/// Constructor that takes one parameter. This initializes the type of the array.
/// </summary>
public ArrayExtension(Type arrayType)
{
Type = arrayType ?? throw new ArgumentNullException(nameof(arrayType));
}
/// <summary>
/// Constructor for writing
/// </summary>
/// <param name="elements">The array to write</param>
public ArrayExtension(Array elements)
{
ArgumentNullException.ThrowIfNull(elements);
_arrayList.AddRange(elements);
Type = elements.GetType().GetElementType();
}
/// <summary>
/// Called to Add an object as a new array item. This will append the
/// object to the end of the array.
/// </summary>View on GitHub (pinned to 81131a70a4)