{"record":{"id":"a109c53a47de06c5","repo":"dotnet/maui","slug":"args-throw-new-argumentnullexception-nameof","errorCode":null,"errorMessage":"_ = args ?? throw new ArgumentNullException(nameof(args));","messagePattern":"_ = args \\?\\? throw new ArgumentNullException\\(nameof\\(args\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs","lineNumber":106,"sourceCode":"\t\t/// </summary>\n\t\tpublic object DragStartingCommandParameter\n\t\t{\n\t\t\tget { return (object)GetValue(DragStartingCommandParameterProperty); }\n\t\t\tset { SetValue(DragStartingCommandParameterProperty, value); }\n\t\t}\n\n\t\tinternal void SendDropCompleted(DropCompletedEventArgs args)\n\t\t{\n\t\t\tif (!_isDragActive)\n\t\t\t{\n\t\t\t\t// this is mainly relevant for Android\n\t\t\t\t// Android fires an Ended action on every single view that has a drop handler\n\t\t\t\t// but we only need one of those DropCompleted actions to make it through\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t_isDragActive = false;\n\t\t\t_ = args ?? throw new ArgumentNullException(nameof(args));\n\n\t\t\tDropCompletedCommand?.Execute(DropCompletedCommandParameter);\n\t\t\tDropCompleted?.Invoke(Parent ?? this, args);\n\t\t}\n\n\t\tinternal DragStartingEventArgs SendDragStarting(View element, Func<IElement?, Point?>? getPosition = null, PlatformDragStartingEventArgs? platformArgs = null)\n\t\t{\n\t\t\tvar args = new DragStartingEventArgs(getPosition, platformArgs);\n\n\t\t\tDragStartingCommand?.Execute(DragStartingCommandParameter);\n\t\t\tDragStarting?.Invoke(element, args);\n\n#pragma warning disable CS0618 // Type or member is obsolete\n\t\t\tif (!args.Handled)\n\t\t\t\targs.Data.PropertiesInternal.Add(\"DragSource\", element);\n#pragma warning restore CS0618 // Type or member is obsolete\n\n#pragma warning disable CS0618 // Type or member is obsolete","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs#L88-L124","documentation":"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.","triggerScenarios":"Platform handler or test code calling SendDropCompleted(null) while _isDragActive is true; custom drag handlers invoking the internal method with a null args.","commonSituations":"Custom platform renderers/handlers for drag-and-drop that forget to construct DropCompletedEventArgs; unit tests simulating drop completion with null.","solutions":["Always construct and pass a DropCompletedEventArgs instance to SendDropCompleted.","In platform handlers, build args from the platform event before forwarding.","In tests, pass `new DropCompletedEventArgs()` rather than null."],"exampleFix":"// before\ngestureRecognizer.SendDropCompleted(null); // throws when drag active\n\n// after\ngestureRecognizer.SendDropCompleted(new DropCompletedEventArgs());","handlingStrategy":"validation","validationCode":"static void SafeSendDropCompleted(DragGestureRecognizer g, DropCompletedEventArgs? args)\n{\n    if (args is null) throw new ArgumentNullException(nameof(args));\n    g.SendDropCompleted(args); // if accessible; else guard before the platform call\n}","typeGuard":"static bool IsValidDropArgs(DropCompletedEventArgs? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Always construct DropCompletedEventArgs before forwarding.","In platform handlers, build args from the platform event object.","In tests, pass new DropCompletedEventArgs(), never null."],"tags":["draganddrop","argumentnull","gesturerecognizer","internal"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}