IDataObject.GetData with non-serializable type returns null
See original GitHub issue.NET version
.NET 7 RC1
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Yes, up to and including .NET 6.
Issue description
Hello,
My name is Norton, and I’m writing on behalf of the WinForms team at DevExpress.
Our customers who were testing our controls with the .NET 7 RC1 runtime reported issues when using our controls’ drag-drop capabilities. Upon further research, we found what seems to be a breaking change in .NET 7: whenever an instance of a non-serializable class is used with the Control.DoDragDrop
method, calling IDataObject.GetData
with that class as a parameter afterwards returns null
rather than the dragged object.
We could not find any issues/PRs or MSDN articles documenting this change. Could you have a look and let us know if this change is intended?
Steps to reproduce
I attached a sample application. To replicate this behavior, run the project and start dragging anywhere on the form. The Debugger.Break
method is called to indicate that the GetData
method returned null
.
If the type of the dragged object is made serializable (e.g. by modifying the using
statement in Form1.cs
), this behavior no longer takes place.
Issue Analytics
- State:
- Created a year ago
- Comments:19 (7 by maintainers)
Top GitHub Comments
@Ashley-Li we have issues in both cases. Drag from desktop and drag of the form, so testing of drag from desktop is also important.
Hi @Ashley-Li ! Although I’m not the author of the sample project, I guess the test is written in a way to use the TDraggableObject (see using on top) where you can easily swap out a serializable and non-serializable object for testing. The data object is set in the mouse down event/override. So dragging a file from the desktop will always return null when calling the GetData method with the typeof(TDraggableObject). To test the behavior, simple click and hold on the form and start dragging.