gong-wpf-dragdrop icon indicating copy to clipboard operation
gong-wpf-dragdrop copied to clipboard

System.Runtime.InteropServices.COMException (0x80004005): A drag operation is already in progress

Open Shifty15 opened this issue 5 years ago • 13 comments

What steps will reproduce this issue?

Unfortunately I'm not able to reproduce it. This exception is thrown randomly. I found same issue (#253) but it's close and I can't see any solution there. This is stack trace from excetion: System.Runtime.InteropServices.COMException (0x80004005): A drag operation is already in progress

A drag operation is already in progress

at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect) at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect) at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects) at System.Windows.DragDrop.DoDragDrop(DependencyObject dragSource, Object data, DragDropEffects allowedEffects) at GongSolutions.Wpf.DragDrop.DragDrop.DragSourceOnMouseMove(Object sender, MouseEventArgs e) in D:\projects\git\gong-wpf-dragdrop\src\GongSolutions.WPF.DragDrop.Shared\DragDrop.cs:line 462 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Environment

  • GongSolutions.WPF.DragDrop v1.1.0
  • Windows OS 10 x64
  • Visual Studio 2017
  • .NET Framework 4.7.2

Shifty15 avatar Mar 26 '19 13:03 Shifty15

I got the same error, while I was testing my application in a VirtualBox VM.

As it turned out, previously to testing the application, I had been dragging and dropping files from my host machine to some folder of the VM machine. This process is notoriously buggy in VirtualBox and it ended up bricking drag and drop operations entirely until the next restart.

Consequently, when I tested my app, I got the System.Runtime.InteropServices.COMException (0x80004005): A drag operation is already in progress error every time, no matter what I did, because the previous drag & drop file operation got stuck, was never completed/cancelled and was blocking any new drag & drop operations for the whole system.

Restarting the VM did the trick, though just restarting the right service might work as well.

lauxjpn avatar Jun 18 '19 02:06 lauxjpn

I am not using Gong (using native WPF controls) and I am getting the same exact error randomly. All specs are the same with the exception of the framework (using 4.6.1). It appears to be a WPF issue in general.

Did you ever come up with a solution to handle?

Tronald avatar Jul 08 '19 15:07 Tronald

Hi, We also faced the same issue, but with no understood cause. We use TeamViewer, so it might be a case similar to the one described @lauxjpn (an interrupted DnD that the OS doesn't acknowledge). Although I can't have confirmation that fixes the issue, I created a derived class from DefaultDragHandler in which TryCatchOccurredException is overriden to log the exception and then returns true (this avoids the re-throw in DragSourceOnMouseMove). This is exposed as a global static resource for ease of use.

Of course, it will probably mean that the drag and drop functionalilty won't work until the machine is rebooted, but in some cases a degraded (but alive) software is better than one which crashes.

IrmatDen avatar Sep 10 '19 15:09 IrmatDen

Hello I also have same problem. This is stack trace.

2020-01-16 10:37:41,304 [v1.4.9.0] [1] ERROR AppLog - Version: 1.4.9.0 | Source: Application.Current.DispatcherUnhandledException System.Runtime.InteropServices.COMException (0x80004005): 8070000c 오류가 발생하여 작업을 완료할 수 없습니다. 위치: MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect) 위치: System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect) 위치: System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects) 위치: System.Windows.DragDrop.DoDragDrop(DependencyObject dragSource, Object data, DragDropEffects allowedEffects) 위치: GongSolutions.Wpf.DragDrop.DragDrop.DragSource_PreviewMouseMove(Object sender, MouseEventArgs e) 위치: System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 위치: System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

Please refer it.

kimhyeonsu avatar Jan 17 '20 06:01 kimhyeonsu

Version 2.4.0 still have this problem. It was caused by some invalid windows state, can be fixed by reboot windows.

I saw there is `try' on line: https://github.com/punker76/gong-wpf-dragdrop/blob/ce3bfe6b34aeec67b5f9f1400fb2646262dd8689/src/GongSolutions.WPF.DragDrop/DragDrop.cs#L560

But it does not catch exception. I guess the exception was triggered by this line:

https://github.com/punker76/gong-wpf-dragdrop/blob/ce3bfe6b34aeec67b5f9f1400fb2646262dd8689/src/GongSolutions.WPF.DragDrop/DragDrop.cs#L540

Exception : A drag operation is already in progress A drag operation is already in progress.

COMException
   at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects)
   at System.Windows.DragDrop.DoDragDrop(DependencyObject dragSource, Object data, DragDropEffects allowedEffects)
   at GongSolutions.Wpf.DragDrop.DragDrop.DoDragSourceMove(Object sender, Point position)
   at GongSolutions.Wpf.DragDrop.DragDrop.DragSourceOnMouseMove(Object sender, MouseEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

cuiliang avatar Aug 24 '21 13:08 cuiliang

@cuiliang And where does it happen? Inside a VM or on real OS?

punker76 avatar Aug 24 '21 14:08 punker76

Same problem here. When TeamViewer is running on our customers computer, they get this drag drop exception. After exiting the TeamViewer application entirely, everything works again.

Lumoryel avatar Aug 24 '21 14:08 Lumoryel

@cuiliang And where does it happen? Inside a VM or on real OS?

Sorry, I dont know. It's automatic reported from customer computer when unhandled exception occured.

I think catch this exception and avoid application crash is enouch.

Thank you ~

cuiliang avatar Aug 24 '21 14:08 cuiliang

@cuiliang I have this problem as well, but I have simply suppressed the exception in my "unhandled exceptions" catch logic. Most of the time it doesn't even effect user experience. Not sure why windows still hasn't fixed the issue, but most of the time it appears it can be ignored.

Tronald avatar Aug 24 '21 18:08 Tronald

@Tronald Thank you, I will try.

cuiliang avatar Aug 24 '21 23:08 cuiliang

@lauxjpn solution fixed it for me. Reboot resolved it. Strange issue for sure.

TWhidden avatar Sep 16 '21 21:09 TWhidden

Just fyi: still happening in 2023, .NET7, random as described above, thanks. Stack trace:

A drag operation is already in progress
 
   at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects)
   at System.Windows.DragDrop.DoDragDrop(DependencyObject dragSource, Object data, DragDropEffects allowedEffects)
   at GongSolutions.Wpf.DragDrop.DragDrop.DoDragSourceMove(Object sender, Func`2 getPosition) in C:\projects\gong-wpf-dragdrop\src\GongSolutions.WPF.DragDrop\DragDrop.cs:line 654
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

RhomGit avatar Nov 19 '23 04:11 RhomGit