Restoring autoConvert behavior in Clipboard APIs - #11837
Open
Shyam-Gupta wants to merge 4 commits into
Open
Conversation
Member
Author
|
Requesting @JeremyKuhne for review. |
Contributor
There was a problem hiding this comment.
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 useIsDataFormatAutoConvert(format)instead of always enablingautoConvert. - Add a unit test asserting
Clipboard.GetText(...)does not auto-convert betweenTextandUnicodeText.
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.
JeremyKuhne
approved these changes
Aug 12, 2026
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 one issue in dotnet/winforms#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 bug dotnet/winforms#14322Customer 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