{"record":{"id":"12a95b1f138ea2a6","repo":"dotnet/maui","slug":"view-throw-new-argumentnullexception-nameof","errorCode":null,"errorMessage":"_ = view ?? throw new ArgumentNullException(nameof(view));","messagePattern":"_ = view \\?\\? throw new ArgumentNullException\\(nameof\\(view\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DragAndDrop/DropEventArgs.cs","lineNumber":19,"sourceCode":"using System;\nusing Microsoft.Maui.Graphics;\n\nnamespace Microsoft.Maui.Controls\n{\n\t/// <summary>\n\t/// Provides data for the <see cref=\"DropGestureRecognizer.Drop\"/> event.\n\t/// </summary>\n\tpublic class DropEventArgs\n\t{\n\t\tFunc<IElement?, Point?>? _getPosition;\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"DropEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <param name=\"view\">The data package associated with the drop.</param>\n\t\tpublic DropEventArgs(DataPackageView view)\n\t\t{\n\t\t\t_ = view ?? throw new ArgumentNullException(nameof(view));\n\t\t\tData = view;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"DropEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <param name=\"view\">The data package associated with the drop.</param>\n\t\t/// <param name=\"getPosition\">Function used to get the position relative a specified <see cref=\"IElement\"/>.</param>\n\t\t/// <param name=\"platformArgs\">The platform-specific data associated with the drag.</param>\n\t\tinternal DropEventArgs(DataPackageView? view, Func<IElement?, Point?>? getPosition, PlatformDropEventArgs platformArgs)\n\t\t{\n\t\t\tData = view ?? new DataPackageView(new DataPackage());\n\t\t\t_getPosition = getPosition;\n\t\t\tPlatformArgs = platformArgs;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the data package associated with the drop event.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DragAndDrop/DropEventArgs.cs#L1-L37","documentation":"DropEventArgs's public constructor throws ArgumentNullException(nameof(view)) when the DataPackageView argument is null. The constructor is the documented entry point for Drop events; a null data package is treated as a programming error. (An internal overload tolerates a null view and substitutes a fresh DataPackageView.)","triggerScenarios":"Constructing `new DropEventArgs(null)` via the public constructor; event-raising code that passes a null DataPackageView.","commonSituations":"Test code raising Drop events without a data package; refactoring that loses the DataPackageView reference before constructing args.","solutions":["Pass a non-null DataPackageView: wrap a DataPackage with `new DataPackageView(new DataPackage())` if empty.","Use the internal overload only if you are framework/platform code and intentionally allow a default package.","Null-check before constructing and supply an empty package."],"exampleFix":"// before\nvar args = new DropEventArgs(null); // throws\n\n// after\nvar args = new DropEventArgs(new DataPackageView(new DataPackage()));","handlingStrategy":"validation","validationCode":"static DropEventArgs MakeDropArgs(DataPackageView? view) =>\n    new(view ?? new DataPackageView(new DataPackage()));","typeGuard":"static bool HasDataPackage(DataPackageView? v) => v is not null;","tryCatchPattern":null,"preventionTips":["Never call the public DropEventArgs ctor with null.","Keep an empty DataPackageView handy: new DataPackageView(new DataPackage()).","Null-check before constructing and supply an empty package."],"tags":["draganddrop","argumentnull","eventargs","constructor"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}