Repository navigation
Restoring autoConvert behavior in Clipboard APIs - #14893
Merged
Merged
Conversation
Issue: Till .NET 9.0, autoConvert was set to true only for FileDrop and Bitmap scenarios. However, since .NET 10, it is being set to true for GetAudioStream, GetFileDropList, GetImage, and GetText APIs inside the private method GetTypedDataIfAvailable. This causes issues with GetText API with mojibake characters as described in the bug. Fix: Just like 9.0, setting autoConvert = true only for FileDrop and Bitmap data formats.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores the historical Clipboard autoConvert behavior (pre-.NET 10) by limiting auto-conversion to FileDrop and Bitmap scenarios, preventing unintended text format conversions that can lead to mojibake/corrupted results in Clipboard.GetText().
Changes:
- Restricts
Clipboard.Get*typed retrieval to only auto-convert forFileDropandBitmapformats. - Adds/updates unit tests and test utilities to validate that text formats are not auto-converted.
- Extracts
TextDataFormat -> DataFormatsmapping into a shared internal helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/util/System.Windows.Forms/Data/TypedDataObject.cs | Implements the TryGetData(format, autoConvert, out T) overload for typed test data objects (previously threw). |
| src/test/util/System.Windows.Forms/Data/TypedAndRuntimeDataObject.cs | Same as above for the managed+runtime test data object implementation. |
| src/test/unit/System.Windows.Forms/System/Windows/Forms/ClipboardTests.cs | Adds coverage for non-auto-conversion between Text/UnicodeText and updates expectations for SetDataObject(string) scenarios. |
| src/System.Windows.Forms/System/Windows/Forms/OLE/ClipboardUtilities.cs | New internal helper to convert TextDataFormat to corresponding DataFormats strings. |
| src/System.Windows.Forms/System/Windows/Forms/OLE/Clipboard.cs | Applies format-based autoConvert policy in GetTypedDataIfAvailable and refactors format conversion usage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
JeremyKuhne
approved these changes
Aug 14, 2026
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
Shyam-Gupta
added a commit
that referenced
this pull request
Aug 26, 2026
Restoring autoConvert behavior in Clipboard APIs (#14893) * Fixes mojibake character issue in bug #14322 Issue: Till .NET 9.0, autoConvert was set to true only for FileDrop and Bitmap scenarios. However, since .NET 10, it is being set to true for GetAudioStream, GetFileDropList, GetImage, and GetText APIs inside the private method GetTypedDataIfAvailable. This causes issues with GetText API with mojibake characters as described in the bug. Fix: Just like 9.0, setting autoConvert = true only for FileDrop and Bitmap data formats. * Parameter list formatting --------- Co-authored-by: Shyam Gupta <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 mojibake character issue in #14322
Description
Till .NET 9.0,
autoConvertwas set to true only forFileDropandBitmapscenarios. However, since .NET 10, it is being set to true forGetAudioStream,GetFileDropList,GetImage, andGetTextAPIs inside the private methodGetTypedDataIfAvailable. This causes issues with GetText API with mojibake characters as described in the bug.Customer Impact
There is no way for the app to know whether the clipboard contents were corrupted or if there is any problem with the API as it didn't get the desired data.
Regression
Yes - from .NET 9.0
Testing
Created a WinForms app to write unicode data on the clipboard and another app to read it. Before the changes, the reader app returned several hits for mojibake characters. After fix, there were none.
Risk
This should be a very low risk change as this behavior was working fine in 9.0 and previous versions.
Microsoft Reviewers: Open in CodeFlow