Fix Clipboard.GetDataObject().GetImage regression for bitmap images#14427
Fix Clipboard.GetDataObject().GetImage regression for bitmap images#14427LeafShi1 wants to merge 8 commits intodotnet:mainfrom
Conversation
src/System.Windows.Forms/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
|
Requesting @JeremyKuhne for his thoughts. |
Should follow exactly what the |
|
@LeafShi1 I'd recommend ensuring that we have test cases for any similar APIs off |
…d test that depended on the old GetData fallback.
The derived APIs exposed by |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs
Show resolved
Hide resolved
src/test/unit/System.Windows.Forms/System/Windows/Forms/ClipboardTests.cs
Outdated
Show resolved
Hide resolved
src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs
Show resolved
Hide resolved
|
Product change looks correct now. Only few changes required in test code. Thanks. |
…jectTests.cs and adding a "delegation relationship" test for the `GetImage` method.
src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs
Outdated
Show resolved
Hide resolved
Shyam-Gupta
left a comment
There was a problem hiding this comment.
Looks good. Pending tasks are to clean up the test code and fix failing tests.
We will need to backport it to .NET 10 for servicing. Thanks.
There was a problem hiding this comment.
Pull request overview
Fixes a regression where Clipboard.GetDataObject().GetImage() returns null for bitmap images after the move to the typed/NRBF clipboard pipeline by updating DataObject.GetImage() to use the typed retrieval API and adding regression coverage.
Changes:
- Updated
DataObject.GetImage()to retrieve bitmap images viaTryGetData<Image>(DataFormats.Bitmap, autoConvert: true, ...). - Updated/added unit tests to validate
GetImage()uses typed retrieval and to validate clipboard bitmap round-tripping viaGetDataObject().GetImage().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/OLE/DataObject.cs | Changes GetImage() implementation to use typed TryGetData<Image> for bitmap retrieval. |
| src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs | Updates GetImage unit test expectations and adds a clipboard round-trip regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs
Outdated
Show resolved
Hide resolved
…jectTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/test/unit/System.Windows.Forms/System/Windows/Forms/DataObjectTests.cs
Outdated
Show resolved
Hide resolved
…tps://github.com/LeafShi1/winforms into Fix_14423_Clipboard.GetDataObject.GetImage_issue
Fixes #14423
Root cause
After PR #11545 moved clipboard to the new typed + NRBF pipeline, bitmap images are stored mainly in the
ITypedDataObjecttyped store, butDataObject.GetImagestill only reads from the legacyGetDatastore, soClipboard.GetDataObject().GetImage()can no longer see those images on .NET 10/11.Proposed changes
Update
public virtual Image? GetImage()to:First attempt
TryGetData<Image>(DataFormats.Bitmap, autoConvert: true, out image)and return that image when available (aligned withClipboard.GetImage()and the new typed/NRBF pipeline).Fall back to
GetData(DataFormats.Bitmap, autoConvert: true)as Image to preserve existing behavior for legacy or non-typed data sources.Add
GetDataObject_GetImage_RoundTripsBitmap:Clipboard.SetImage(bitmap)thenClipboard.GetDataObject()→DataObject.Assert
dataObject.GetImage()returns a Bitmap with the expected size and pixel value, andClipboard.ContainsImage()is true.Customer Impact
Clipboard.GetDataObject().GetImage()on .NET 10/11 can copy and paste bitmap images correctly again, just like on .NET 9, with no app changes needed.Regression?
Risk
Screenshots
Before
Copy an image to the clipboard, run the code
GetImage()returns null.After
GetImage()returns aSystem.Drawing.Bitmap.Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow