Fix Clipboard.GetDataObject().GetImage regression for bitmap images#14427
Open
LeafShi1 wants to merge 3 commits intodotnet:mainfrom
Open
Fix Clipboard.GetDataObject().GetImage regression for bitmap images#14427LeafShi1 wants to merge 3 commits intodotnet:mainfrom
LeafShi1 wants to merge 3 commits intodotnet:mainfrom
Conversation
Shyam-Gupta
reviewed
Apr 1, 2026
src/System.Windows.Forms/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
Member
|
Requesting @JeremyKuhne for his thoughts. |
Member
Should follow exactly what the |
Member
|
@LeafShi1 I'd recommend ensuring that we have test cases for any similar APIs off |
…d test that depended on the old GetData fallback.
Member
Author
The derived APIs exposed by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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