Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to Clipboard.GetData() as the specified format #9180

Closed
Philip-Wang01 opened this issue May 26, 2023 · 6 comments
Closed

Failed to Clipboard.GetData() as the specified format #9180

Philip-Wang01 opened this issue May 26, 2023 · 6 comments
Assignees
Labels
💥 regression-preview Regression from a preview release 🚧 work in progress Work that is current in progress

Comments

@Philip-Wang01
Copy link
Contributor

Philip-Wang01 commented May 26, 2023

.NET version

.NET 8.0.100-preview.5.23274.2

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, it works in .NET 6.0/7.0/8.0.100-preview5.23253.20. Maybe caused by: #9088

Issue description

Testapp: Testapp.zip

.NET 8.0
image

.NET 7.0
image

Steps to reproduce

  1. Create a WinForms .NET Core project.
  2. Add a button control to form designer, double click button1 and type below code in function button1_Click.
Color c = System.Drawing.Color.Black;
string format = "testabc";
Clipboard.Clear();
Clipboard.SetData(format, c);
Clipboard.ContainsData(format);
object ob = null;
ob = Clipboard.GetData(format);
  1. Add a breakpoint at the end of the event, build and run the application, click button1.
  2. Observe the value of ob.
@Philip-Wang01 Philip-Wang01 added 💥 regression-preview Regression from a preview release untriaged The team needs to look at this issue in the next triage labels May 26, 2023
@elachlan
Copy link
Contributor

@JeremyKuhne I guess you are still working through the binary formatter changes?

#6267

@JeremyKuhne JeremyKuhne self-assigned this May 30, 2023
@JeremyKuhne JeremyKuhne added 🚧 work in progress Work that is current in progress and removed untriaged The team needs to look at this issue in the next triage labels May 30, 2023
@merriemcgaw merriemcgaw added this to the 8.0 Preview6 milestone May 30, 2023
@JeremyKuhne
Copy link
Member

This doesn't reproduce for me with the current bits when the BinaryFormatter is enabled, which it should be. When it is disabled, it returns null. @Philip-Wang01 can you debug with first chance exceptions to see if you're getting a NotSupportedException with the binary formatter?

Some notes on the BinaryFormatter being disabled:

Unfortunately, the OLE clipboard window always swallows errors when setting data (in WM_RENDERFORMAT it always returns an LRESULT of 0). So setting always succeeds. If we try to get the data out it will fail with CLIPBRD_E_BAD_DATA, which we swallow. I've added some debug assistance around that in the #9195 PR.

I'm thinking through what we might be able to do to surface that the BinaryFormatter has been disabled and will likely create an issue to track soon.

@JeremyKuhne JeremyKuhne added the 📭 waiting-author-feedback The team requires more information from the author label May 30, 2023
@Philip-Wang01
Copy link
Contributor Author

Philip-Wang01 commented May 31, 2023

@JeremyKuhne I have built debug and release dlls under winforms repro. Get NotSupportedException with the binary formatter when using debug dlls and don't get NotSupportedException when using release dlls.
I also found that when I get NotSupportedException, clicking on the “Copy Details” gives an error message, could you help to see this phenomenon?

bandicam.2023-05-30.23-45-35-515.mp4

image

@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label May 31, 2023
@Philip-Wang01
Copy link
Contributor Author

Verified this test steps in the latest .Net 8.0 SDK build: 8.0.100-preview.6.23307.24, it was fixed. However, this issue still affects automated test cases and will be updated after investigation.
image
Automation test cases:
image

@Philip-Wang01
Copy link
Contributor Author

Philip-Wang01 commented Jun 29, 2023

After investigation, the test cases failed for similar reasons as 9322.
This test case is a "console application", not a "winforms application". It can be fixed when <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization> is added in the project file.
But the status of this issue is still work in progress, @JeremyKuhne do we still need to keep the issue open?

@JeremyKuhne
Copy link
Member

@Philip-Wang01 we don't need it open, I'm going to close it. Thanks for the heads up.

@ghost ghost removed this from the 8.0 Preview7 milestone Jun 29, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💥 regression-preview Regression from a preview release 🚧 work in progress Work that is current in progress
Projects
None yet
Development

No branches or pull requests

5 participants