Repository navigation
Closed
Labels
💥 regression-releaseRegression from a public release🚧 work in progressWork that is current in progressarea-ClipboardIssues related to Clipboardservicing-approved.NET Shiproom approved the PR for merge
Milestone
Description
Description
Clipboard.SetDataObject method doesn't place a custom DataObject into the clipboard.
Reproduction Steps
- Create a .NET Framework WinForms (or WPF) project.
- Create a custom DataObject class descendant:
public class SomeDataObject : DataObject {
public static string Format = "SomeDataObjectId";
public override string[] GetFormats() {
return new string[] { Format };
}
}
- Call the
Clipboard.SetDataObject(new SomeDataObject());method to add the SomeDataObject's class instance into the clipboard.
Expected behavior
SomeDataObject is added into the clipboard
And Clipboard.GetDataObject().GetDataPresent(SomeDataObject.Format) is true
Actual behavior
The clipboard doesn't contain the SomeDataObject instance
And Clipboard.GetDataObject().GetDataPresent(SomeDataObject.Format) is false
Regression?
Yes, in .NET 8 everything works.
Known Workarounds
No response
Impact
No response
Configuration
$ dotnet --info
.NET SDK:
Version: 9.0.100-rc.2.24474.11
Commit: 315e1305db
Workload version: 9.0.100-manifests.4872d5d5
MSBuild version: 17.12.0-preview-24473-03+fea15fbd1
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\
Host:
Version: 9.0.0-rc.2.24473.5
Architecture: x64
Commit: 990ebf52fc
.NET SDKs installed:
9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other information
No response
Metadata
Metadata
Assignees
Labels
💥 regression-releaseRegression from a public release🚧 work in progressWork that is current in progressarea-ClipboardIssues related to Clipboardservicing-approved.NET Shiproom approved the PR for merge


Activity
miloush commentedon Nov 11, 2024
Please include a repro project. This seems like an unusual way to use data objects. Perhaps the regression is because of the binary formatter removal? https://devblogs.microsoft.com/dotnet/binaryformatter-removed-from-dotnet-9/.
Kuldeep-MS commentedon Nov 11, 2024
@akhromushkin After following your reproduction steps, I encountered the error shown below. Could you please provide more detailed steps?

akhromushkin commentedon Nov 11, 2024
Perhaps is more related to WinForms. So I have attached several projects:
Issue_10049_WPF.zip
Issue_10049_WinForms.zip
BlueBSH commentedon Nov 21, 2024
This issue still exists in the RTM GA version of .NET9.0.0
miloush commentedon Nov 21, 2024
This is all Winforms classes and should be moved to the Winforms repo.
JeremyKuhne commentedon Jan 15, 2025
The WPF repro given is actually using the WinForms Clipboard class. You can't derive the
DataObjectclass inSystem.Windows.I'm not seeing this with the latest fix for the Clipboard, but haven't root caused it yet.
@lonitra fyi
JeremyKuhne commentedon Jan 16, 2025
@akhromushkin
There are two things going on here. The first is an issue with how we're setting up the data to put it on the clipboard. Our constructor for
DataObjectisn't doing the right thing when you construct from anotherDataObject. That said, there is a secondary problem that you should have hit if we hadn't made that mistake.What was intended was related to the change in .NET 9 to use
ComWrappersfor OLE interop. We made the switch as built-in COM isn't available when trimming or using AOT. Changing toComWrappersbreaks implicit casting back to your originalDataObject(which only built-in COM handles). To make these scenarios still work we manually extract the originalDataObjectprovided and return it. Which is what will happen when the February servicing release for .NET 9 goes out.Doing so does give different behavior unfortunately as talking to a
DataObjectthrough its native interface gives different results than talking to it directly. You can see this in this case by creating the derivedDataObjectand callGetDataPresentdirectly on it, which will return false.To make the repro work in the current .NET 9 bits and after February:
Please tag me directly to help get my attention on responses.
Don't unwrap wrapped DataObject inner data store
Don't unwrap wrapped DataObject inner data store (#12800)
Don't unwrap wrapped DataObject inner data store (dotnet#12800)
akhromushkin commentedon Jan 21, 2025
@JeremyKuhne
Thanks for explaining the cause of the problem and WA. I think it should work for our purposes.