Skip to content

Restoring autoConvert behavior in Clipboard APIs - #14893

Merged
Shyam-Gupta merged 2 commits into
mainfrom
dev/shgu/clipMain
Aug 14, 2026
Merged

Shyam-Gupta merged 2 commits into
mainfrom
dev/shgu/clipMain

Conversation

@Shyam-Gupta

@Shyam-Gupta Shyam-Gupta commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Fixes mojibake character issue in #14322

Description

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.

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

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.
@Shyam-Gupta Shyam-Gupta self-assigned this Aug 14, 2026
@Shyam-Gupta
Shyam-Gupta requested a review from a team as a code owner August 14, 2026 19:04
@Shyam-Gupta
Shyam-Gupta requested review from JeremyKuhne and a lite review from Copilot August 14, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for FileDrop and Bitmap formats.
  • Adds/updates unit tests and test utilities to validate that text formats are not auto-converted.
  • Extracts TextDataFormat -> DataFormats mapping 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]>
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

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]>
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants