{"record":{"id":"197bee2e760f0b95","repo":"unoplatform/uno","slug":"a-dragdropextension-has-already-been-enabled","errorCode":null,"errorMessage":"A DragDropExtension has already been enabled","messagePattern":"A DragDropExtension has already been enabled","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Uno.UI/ts/Windows/ApplicationModel/DataTransfer/DragAndDropExtension.ts","lineNumber":26,"sourceCode":"\t\tprivate static _current: DragDropExtension;\n\t\tprivate static _nextDropId: number;\n\n\t\tprivate _dropHandler: any;\n\n\t\tprivate _pendingDropId: number;\n\t\tprivate _pendingDropData: DataTransfer;\n\n\t\tpublic static enable(pArgs: number): void {\n\t\t\tif (!DragDropExtension._dispatchDropEventMethod) {\n\t\t\t\tif ((<any>globalThis).DotnetExports !== undefined) {\n\t\t\t\t\tDragDropExtension._dispatchDropEventMethod = (<any>globalThis).DotnetExports.UnoUI.Windows.ApplicationModel.DataTransfer.DragDrop.Core.DragDropExtension.OnNativeDropEvent;\n\t\t\t\t} else {\n\t\t\t\t\tthrow `DragDropExtension: Unable to find dotnet exports`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (DragDropExtension._current) {\n\t\t\t\tthrow new Error(\"A DragDropExtension has already been enabled\");\n\t\t\t}\n\n\t\t\tDragDropExtension._dispatchDragDropArgs = pArgs;\n\t\t\tDragDropExtension._nextDropId = 1;\n\t\t\tDragDropExtension._current = new DragDropExtension();\n\t\t}\n\n\t\tpublic static disable(pArgs: number): void {\n\t\t\tif (DragDropExtension._dispatchDragDropArgs != pArgs) {\n\t\t\t\tthrow new Error(\"The current DragDropExtension does not match the provided args\");\n\t\t\t}\n\t\t\t\n\t\t\tDragDropExtension._current.dispose();\n\t\t\tDragDropExtension._current = null;\n\t\t\tDragDropExtension._dispatchDragDropArgs = null;\n\t\t}\n\n\t\tconstructor() {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/Uno.UI/ts/Windows/ApplicationModel/DataTransfer/DragAndDropExtension.ts#L8-L44","documentation":"Thrown by DragDropExtension.enable when the static _current field is already non-null, meaning a DragDropExtension instance is already active. This is a singleton-enforcement guard: only one drag-drop extension can own the DOM event listeners at a time.","triggerScenarios":"C# calls enable() twice without a matching disable() in between — e.g. two UI elements both registered a DragDropExtension, or enable was called from overlapping async paths without proper disable.","commonSituations":"Multiple DropBox/ListView controls each initializing their own DragDropExtension; a re-enable without disable after a page navigation or visual-tree rebuild; a race where enable is called concurrently.","solutions":["Call disable(pArgs) to tear down the previous DragDropExtension before calling enable again.","Ensure only one DragDropExtension is enabled at a time in the WASM app; share a single extension across drop targets.","Verify that the previous enable/disable lifecycle completed (disable sets _current = null) before re-enabling."],"exampleFix":"// before: enable called twice → throws on second\nDragDropExtension.enable(args1);\nDragDropExtension.enable(args2); // _current already set\n\n// after: disable first\nDragDropExtension.enable(args1);\n// ... use it ...\nDragDropExtension.disable(args1);\nDragDropExtension.enable(args2);","handlingStrategy":"validation","validationCode":"// Check if an extension is already active before enabling\nif (!(<any>DragDropExtension)._current) {\n    DragDropExtension.enable(pArgs);\n} else {\n    // already enabled — disable first or skip\n}","typeGuard":null,"tryCatchPattern":"try {\n    DragDropExtension.enable(pArgs);\n} catch (e) {\n    if (e.message === 'A DragDropExtension has already been enabled') {\n        DragDropExtension.disable(existingArgs);\n        DragDropExtension.enable(pArgs);\n    } else { throw e; }\n}","preventionTips":["Always balance enable/disable calls; track the active args.","Share a single DragDropExtension across multiple drop targets instead of enabling per-target.","Disable the extension in the managed Unloaded/dispose path."],"tags":["wasm","drag-and-drop","singleton","lifecycle","typescript"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}