C# IDataObject拖放问题,从_ComObject进行强制转换

C# IDataObject拖放问题,从_ComObject进行强制转换,c#,.net,drag-and-drop,ipc,marshalling,C#,.net,Drag And Drop,Ipc,Marshalling,我遇到了一个涉及以下场景的问题,应用程序A有一个DataGridView,从中选择对象。它们被拖到应用程序B内的DataGridView中,对象被复制到新列表中。以下是应用程序A中准备dragdrop的代码: ArrayList ToDrag = this.GetSelectedBoundItems(); DataObject data = new DataObject(ToDrag); this.DoDragDrop(data, DragDropEff

我遇到了一个涉及以下场景的问题,应用程序A有一个DataGridView,从中选择对象。它们被拖到应用程序B内的DataGridView中,对象被复制到新列表中。以下是应用程序A中准备dragdrop的代码:

       ArrayList ToDrag = this.GetSelectedBoundItems();
       DataObject data = new DataObject(ToDrag);
       this.DoDragDrop(data, DragDropEffects.Move | DragDropEffects.Copy);
问题:接收端无法获取ArrayList。以下是代码:

 //formats has the value of "System.Collections.ArrayList"
 var formats = myRetrievedObject.GetFormats();

 //candoit has the value "true"
 var candoit = myRetrievedObject.GetDataPresent(typeof(ArrayList));

 //DraggedItems is of type "System.__ComObject"
 var DraggedItems = myRetrievedObject.GetData(typeof(ArrayList));

 //this returns null.  I 'think' this should work
 ArrayList DraggedItems2 = myRetrievedObject.GetData(typeof(ArrayList)) as ArrayList;

 //This throws an exception (see below)
 ArrayList DraggedItems2 = (ArrayList)myRetrievedObject.GetData(typeof(ArrayList)) as ArrayList;
这个过去可以工作。发生了两件事,我们从.NET 2跳到.NET 4,这个代码被翻译成C++ .net,

我不确定我错过了什么。这些数据应该被转换成一个数组列表

谢谢你的帮助

编辑这是演员阵容中的例外文本

DfResultsControl.dll中发生类型为“System.InvalidCastException”的第一次意外异常


其他信息:无法将类型为“System.\u ComObject”的COM对象强制转换为类型为“System.Collections.ArrayList”的类。表示COM组件的类型实例不能转换为不表示COM组件的类型;但是,只要底层COM组件支持对接口IID的QueryInterface调用,它们就可以转换为接口。

使(数据)对象可序列化可以解决我的问题

是的,但我不能完全记得我做了什么。我{非常确定}问题是我拖动的项目不可序列化,它们必须用于普通的对象拖放。即使您将它们标记为可序列化,对象中的所有类型都必须是可序列化的。@SpectralGhost,如果这不起作用或不适用,请告诉我,我将深入研究代码并尝试记住原因。