question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

DXApplication1.zip

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kant2002commented, Oct 14, 2022

@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.

2reactions
StefanKoellcommented, Oct 14, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - IDataObject.GetData() always returns null with my class
I have a class which I marked as [Serializable] that I'm trying to copy through the clipboard. Calling GetData() always returns null. Copy...
Read more >
Saving and obtaining custom objects to/from Windows ...
Introduction. This article shows, how to save an instance of a custom C#.NET class (any class) to a clipboard. It explains what requirements ......
Read more >
How to: Add Data to the Clipboard - Windows Forms .NET ...
An object must be serializable for it to be put on the Clipboard. To make a type serializable, mark it with the SerializableAttribute...
Read more >
Most controls' drag-drop capabilities no longer work in . ...
We documented this issue in the dotnet/winforms GitHub repository: IDataObject.GetData with non-serializable type returns null #7864.
Read more >
Non-Serializable fields Null when entering Play mode
I'm using a class SomeClass from some c# library in my gameobject script. It doesn't have the Serializable interface.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found