{"record":{"id":"ca1a6964945782fb","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-arraytype","errorCode":null,"errorMessage":"ArgumentNullException(nameof(arrayType))","messagePattern":"ArgumentNullException\\(nameof\\(arrayType\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ArrayExtension.cs","lineNumber":34,"sourceCode":"    [ContentProperty(\"Items\")]\n    [MarkupExtensionReturnType(typeof(Array))]\n    public class ArrayExtension : MarkupExtension\n    {\n        private readonly ArrayList _arrayList = new ArrayList();\n\n        /// <summary>\n        /// Constructor that takes no parameters. This creates an empty array.\n        /// </summary>\n        public ArrayExtension()\n        {\n        }\n\n        /// <summary>\n        /// Constructor that takes one parameter. This initializes the type of the array.\n        /// </summary>\n        public ArrayExtension(Type arrayType)\n        {\n            Type = arrayType ?? throw new ArgumentNullException(nameof(arrayType));\n        }\n\n        /// <summary>\n        /// Constructor for writing\n        /// </summary>\n        /// <param name=\"elements\">The array to write</param>\n        public ArrayExtension(Array elements)\n        {\n            ArgumentNullException.ThrowIfNull(elements);\n\n            _arrayList.AddRange(elements);\n            Type = elements.GetType().GetElementType();\n        }\n\n        /// <summary>\n        /// Called to Add an object as a new array item. This will append the\n        /// object to the end of the array.\n        /// </summary>","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ArrayExtension.cs#L16-L52","documentation":"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.","triggerScenarios":"Calling new ArrayExtension((Type)null) — directly or via reflection/activator from a XAML parser or serializer passing a null Type.","commonSituations":"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.","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."],"exampleFix":"// before\nvar ext = new ArrayExtension(ResolveType(\"my:Widget[]\")); // ResolveType may return null\n// after\nvar t = ResolveType(\"my:Widget[]\") ?? throw new InvalidOperationException(\"Array element type could not be resolved\");\nvar ext = new ArrayExtension(t);","handlingStrategy":"validation","validationCode":"if (arrayType is null) throw new ArgumentException(\"arrayType must be a resolved Type\", nameof(arrayType));\nvar ext = new ArrayExtension(arrayType);","typeGuard":"bool IsValidArrayType(Type t) => t is not null;","tryCatchPattern":"try { var ext = new ArrayExtension(arrayType); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"arrayType\") { /* handle unresolved type */ }","preventionTips":["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."],"tags":["null-argument","constructor","xaml","markup-extension"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}