unoplatform/uno · error · ArgumentNullException

elements

Error message

elements

What it means

ArgumentNullException thrown by the ArrayExtension markup extension (System.Xaml, ported from Mono) when its ArrayExtension(Array elements) constructor is called with a null array. x:ArrayExtension is the XAML construct used to build an array inline in markup; the constructor defensively rejects a null source array. The parameter name 'elements' identifies which argument is null.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/ArrayExtension.cs:48

using Uno.Xaml.Schema;

namespace System.Windows.Markup
{
	[MarkupExtensionReturnType (typeof (Array))]
	[ContentProperty ("Items")]
	// [System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyPresentationFramework_3_5)]
	public class ArrayExtension : MarkupExtension
	{
		public ArrayExtension ()
		{		
			items = new ArrayList ();
		}

		public ArrayExtension (Array elements)
		{
			if (elements == null)
			{
				throw new ArgumentNullException ("elements");
			}

			Type = elements.GetType ().GetElementType ();
			items = new ArrayList (elements);
		}

		public ArrayExtension (Type arrayType)
		{
			if (arrayType == null)
			{
				throw new ArgumentNullException ("arrayType");
			}

			Type = arrayType;
			items = new ArrayList ();
		}

		[ConstructorArgument ("arrayType")]

View on GitHub (pinned to 0418340488)

Solutions

  1. Pass a non-null Array to the constructor; null-check at the call site before constructing.
  2. If the source may legitimately be null, return early or use the parameterless ArrayExtension() and add items via Items.
  3. Add a guard at the caller so a null never reaches the constructor.

Example fix

// before
var ext = new ArrayExtension(maybeNullArray);

// after
var ext = maybeNullArray is null
    ? new ArrayExtension(typeof(int))
    : new ArrayExtension(maybeNullArray);
Defensive patterns

Strategy: validation

Validate before calling

static ArrayExtension SafeArrayExt(Array src) => src is null ? new ArrayExtension() : new ArrayExtension(src);

Type guard

static bool IsNonEmptyArray(object o) => o is Array { Length: > 0 };

Try / catch

try { var ext = new ArrayExtension(src); } catch (ArgumentNullException ex) when (ex.ParamName == "elements") { ext = new ArrayExtension(); }

Prevention

When it happens

Trigger: Programmatic construction 'new ArrayExtension((Array)null)' or a code path that resolves the array argument to null before invoking the constructor.

Common situations: Code-generated or reflection-driven instantiation passing null, a binding that yields null feeding the constructor, or a test invoking the constructor directly without a value.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/4dbccf94ce680834. Report an issue: GitHub.