Skip to content

Restoring autoConvert behavior in Clipboard APIs - #11837

Open
Shyam-Gupta wants to merge 4 commits into
mainfrom
dev/shgu/autoConvert
Open

Restoring autoConvert behavior in Clipboard APIs#11837
Shyam-Gupta wants to merge 4 commits into
mainfrom
dev/shgu/autoConvert

Conversation

@Shyam-Gupta

@Shyam-Gupta Shyam-Gupta commented Aug 12, 2026

Copy link
Copy Markdown
Member

Fixes one issue in dotnet/winforms#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 bug dotnet/winforms#14322

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 WPF 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

@Shyam-Gupta
Shyam-Gupta requested a review from a team August 12, 2026 21:06
@Shyam-Gupta
Shyam-Gupta requested a review from a team as a code owner August 12, 2026 21:06
Copilot AI lite review requested due to automatic review settings August 12, 2026 21:06
@Shyam-Gupta Shyam-Gupta self-assigned this Aug 12, 2026
@dotnet-policy-service dotnet-policy-service Bot added the PR metadata: Label to tag PRs, to facilitate with triage label Aug 12, 2026
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

Requesting @JeremyKuhne for review.

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 pre-.NET 10 Clipboard retrieval behavior by ensuring autoConvert is only enabled for formats that historically relied on it (FileDrop and Bitmap), preventing unintended text format conversion that can result in mojibake.

Changes:

  • Update Clipboard.GetTypedDataIfAvailable<T> to use IsDataFormatAutoConvert(format) instead of always enabling autoConvert.
  • Add a unit test asserting Clipboard.GetText(...) does not auto-convert between Text and UnicodeText.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/ClipboardTests.cs Adds coverage to verify GetText does not auto-convert between auto-convertible text formats.
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs Fixes the regression by applying the existing IsDataFormatAutoConvert policy to typed clipboard retrieval APIs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants