Gong-wpf-dragdrop: Dragging data between two instances of the application causes Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED)) exception

Created on 18 Feb 2013  ·  3Comments  ·  Source: punker76/gong-wpf-dragdrop

_Original author: [email protected] (December 07, 2010 14:58:50)_

What steps will reproduce the problem?

  1. Implement IDragSource.
  2. Start drag of data (row from wpf datagrid in my case)
  3. Add clone of user-defined data to the IDragInfo.Data object in StartDrag.
  4. Drag over the same datagrid in second instance of application.

What is the expected output? What do you see instead?

The expected output would be the cloned data added to the datagrid. In the DragOver and Drop events I would handle any data issues. However, I never get that far because the Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED)) exception is raised by the O/S at line 135 in GongSolutions.Wpf.DragDrop.DropInfo.cs (code is Data = (e.Data.GetDataPresent(dataFormat)) ? e.Data.GetData(dataFormat) : e.Data;).

What version of the product are you using? On what operating system?
0.1.3 (Assembly version) - I built from source
Windows XP

Please provide any additional information below.

Exception details follow:

System.Runtime.InteropServices.COMException was unhandled by user code
Message=Invalid tymed (Exception from HRESULT: 0x80040069 (DV_E_TYMED))
Source=mscorlib
ErrorCode=-2147221399
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Windows.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format)
at GongSolutions.Wpf.DragDrop.DropInfo..ctor(Object sender, DragEventArgs e, DragInfo dragInfo)
at GongSolutions.Wpf.DragDrop.DragDrop.DropTarget_PreviewDragOver(Object sender, DragEventArgs e)
at GongSolutions.Wpf.DragDrop.DragDrop.DropTarget_PreviewDragEnter(Object sender, DragEventArgs e)
at System.Windows.DragEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
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.RaiseEvent(RoutedEventArgs e)
at System.Windows.OleDropTarget.RaiseDragEvent(RoutedEvent dragEvent, Int32 dragDropKeyStates, Int32& effects, DependencyObject target, Point targetPoint)
at System.Windows.OleDropTarget.MS.Win32.UnsafeNativeMethods.IOleDropTarget.OleDragOver(Int32 dragDropKeyStates, Int64 point, Int32& effects)
InnerException:

_Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=29_

Bug Imported from google code

Most helpful comment

I faced the DV_E_TYMED exception problem in an App I am developing and I'd like to share the solution I found. Here attached you can find the files from your project that I modified in order to fix the issue.
Basically when dragging objects from one Application to another, you need to use COM and COM requires objects to be Serializable to be exchanged correctly.
When using DataObject you cannot just pass a DataFromat you created, cause COM won't know anything about it. I instead created a wrapper class (DragDropDataWrapper) which is marked as [Serializable] and implements ISerializable. Then each time I need to create a DataObject I do : new DataObject(new DragDropDataWrapper(data)). On the drop side I can now retrieve my data using DataFormat.Serializable, which is COM recognizable.
I had to fix other minor things to make the example work, i.e. manage the case when DragInfo is null.
If you check the BoundTree example it should now work cross application.
CrossApplicationDragDropFix.zip

All 3 comments

_From [email protected] on December 07, 2010 15:25:00_
A little more info....

It appears the real problem is when I set the IDragInfo.Data to a System.Windows.DataObject object. I am attaching a sample application to demo the problem.

To see the error, perform the following steps. Run two instances of the application, attempt to drag an item from the listbox between the two instances.

The reason I am using a DataObject is I need to allow for file-drop to the O/S as well.

I faced the DV_E_TYMED exception problem in an App I am developing and I'd like to share the solution I found. Here attached you can find the files from your project that I modified in order to fix the issue.
Basically when dragging objects from one Application to another, you need to use COM and COM requires objects to be Serializable to be exchanged correctly.
When using DataObject you cannot just pass a DataFromat you created, cause COM won't know anything about it. I instead created a wrapper class (DragDropDataWrapper) which is marked as [Serializable] and implements ISerializable. Then each time I need to create a DataObject I do : new DataObject(new DragDropDataWrapper(data)). On the drop side I can now retrieve my data using DataFormat.Serializable, which is COM recognizable.
I had to fix other minor things to make the example work, i.e. manage the case when DragInfo is null.
If you check the BoundTree example it should now work cross application.
CrossApplicationDragDropFix.zip

Was this page helpful?
0 / 5 - 0 ratings