Skip to content

Restoring autoConvert behavior in Clipboard APIs - #11837

Merged
dipeshmsft merged 4 commits into
mainfrom
dev/shgu/autoConvert
Aug 21, 2026
Merged

dipeshmsft merged 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.

@Shyam-Gupta

Copy link
Copy Markdown
Member Author

For reference, similar commit for WinForms: dotnet/winforms#14893

cc: @dipeshmsft, @pranav-gupta-msft

@harshit7962 harshit7962 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dipeshmsft
dipeshmsft merged commit 1cfc37f into main Aug 21, 2026
8 checks passed
@dipeshmsft
dipeshmsft deleted the dev/shgu/autoConvert branch August 21, 2026 10:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 22, 2026
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown

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

Shyam-Gupta added a commit that referenced this pull request Aug 27, 2026
Restoring autoConvert behavior in Clipboard APIs (#11837)

* Restoring autoConvert to .NET 8.0 in Clipboard APIs

* Added unit test

* Also setting autoConvert to false in one of the TryGetData overload.

* Formatting

Co-authored-by: Shyam Gupta <[email protected]>
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

dipeshmsft pushed a commit that referenced this pull request Sep 14, 2026
Restoring autoConvert behavior in Clipboard APIs (#11837)

* Restoring autoConvert to .NET 8.0 in Clipboard APIs

* Added unit test

* Also setting autoConvert to false in one of the TryGetData overload.

* Formatting

Co-authored-by: Shyam Gupta <[email protected]>
isharrrry added a commit to isharrrry/WPFOnLinux that referenced this pull request Sep 20, 2026
- UPSTREAM-PROVENANCE.md §1.1:逐件字节验证 —— 6414 件里 6384 件与 1cfc37f 逐字节相同、
  29 件仅换行不同(非 git 搬入的伪影)、1 件是本仓刻意改的 .gitattributes、954 件为已登记裁剪
  ⇒ 精确 commit 由「未定」改为「已钉死」,并给出复算命令
- README:上游出处那条改为「已钉死」;目录导航里写明「账一:构建只读 upstream/wpf/**,根目录那份不使用」
  并指出 53 MB 的 windows-results.json 只能在 Windows 侧重录(账三口径)
- ROUTES.md §8:把「上游化/去重」标为按裁定暂缓(只保持现状 + 文档写清)
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.

5 participants