Scenario
I found this question when I was trying to debug this problem:
I was dropping into a WinForms application, where inside the Drop event handler, the object I received was a System.Windows.Forms.IDataObject
However, I was using a library to do the heavy lifting of the Drop event, and it expected a object of type System.Windows.IDataObject
. I was not able to edit the library source code.
Problem
If I tried to simply cast between the types ...
// data is of type System.Windows.Forms.IDataObject
var newData = (System.Windows.IDataObject)data; // debugger exits function after this line of code
... the debugger would just exit the function at that line of code without error. None of the code after that line would execute.
Solution
I created a proxy method that I called inside my WinForms event handler. The constructor for System.Windows.DataObject
will accept a System.Windows.Forms.DataObject
.
public void DropEventProxy(System.Windows.Forms.IDataObject data)
{
System.Windows.IDataObject newData = new System.Windows.DataObject(data);
LibraryDropEventHandler(newData);
}
public string LibraryDropEventHandler(System.Windows.IDataObject data);