dotnet/maui · error · ArgumentNullException

_ = args ?? throw new ArgumentNullException(nameof(args));

Error message

_ = args ?? throw new ArgumentNullException(nameof(args));

What it means

DragGestureRecognizer.SendDropCompleted throws ArgumentNullException(nameof(args)) if the DropCompletedEventArgs is null. Note the early `if (!_isDragActive) return;` means the null check only runs when a drag is active; calling SendDropCompleted(null) while a drag is active throws. This guards the internal platform-callback path.

Source

Thrown at src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs:106

		/// </summary>
		public object DragStartingCommandParameter
		{
			get { return (object)GetValue(DragStartingCommandParameterProperty); }
			set { SetValue(DragStartingCommandParameterProperty, value); }
		}

		internal void SendDropCompleted(DropCompletedEventArgs args)
		{
			if (!_isDragActive)
			{
				// this is mainly relevant for Android
				// Android fires an Ended action on every single view that has a drop handler
				// but we only need one of those DropCompleted actions to make it through
				return;
			}

			_isDragActive = false;
			_ = args ?? throw new ArgumentNullException(nameof(args));

			DropCompletedCommand?.Execute(DropCompletedCommandParameter);
			DropCompleted?.Invoke(Parent ?? this, args);
		}

		internal DragStartingEventArgs SendDragStarting(View element, Func<IElement?, Point?>? getPosition = null, PlatformDragStartingEventArgs? platformArgs = null)
		{
			var args = new DragStartingEventArgs(getPosition, platformArgs);

			DragStartingCommand?.Execute(DragStartingCommandParameter);
			DragStarting?.Invoke(element, args);

#pragma warning disable CS0618 // Type or member is obsolete
			if (!args.Handled)
				args.Data.PropertiesInternal.Add("DragSource", element);
#pragma warning restore CS0618 // Type or member is obsolete

#pragma warning disable CS0618 // Type or member is obsolete

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Always construct and pass a DropCompletedEventArgs instance to SendDropCompleted.
  2. In platform handlers, build args from the platform event before forwarding.
  3. In tests, pass `new DropCompletedEventArgs()` rather than null.

Example fix

// before
gestureRecognizer.SendDropCompleted(null); // throws when drag active

// after
gestureRecognizer.SendDropCompleted(new DropCompletedEventArgs());
Defensive patterns

Strategy: validation

Validate before calling

static void SafeSendDropCompleted(DragGestureRecognizer g, DropCompletedEventArgs? args)
{
    if (args is null) throw new ArgumentNullException(nameof(args));
    g.SendDropCompleted(args); // if accessible; else guard before the platform call
}

Type guard

static bool IsValidDropArgs(DropCompletedEventArgs? a) => a is not null;

Prevention

When it happens

Trigger: Platform handler or test code calling SendDropCompleted(null) while _isDragActive is true; custom drag handlers invoking the internal method with a null args.

Common situations: Custom platform renderers/handlers for drag-and-drop that forget to construct DropCompletedEventArgs; unit tests simulating drop completion with null.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/a109c53a47de06c5. Report an issue: GitHub.