[release/11.0] AppContext switch for restoring exception handling behavior in WPF Clipboard APIs - #15035
Open
github-actions[bot] wants to merge 1 commit into
Open
[release/11.0] AppContext switch for restoring exception handling behavior in WPF Clipboard APIs#15035github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…ipboard APIs (#15022) * Fixes empty string scenario in bug #14322 Fix: Added a new AppContext switch: "Windows.Clipboard.ThrowExceptionsForGetAPIs" When set, the Clipboard Get* APIs will throw exception during a Clipboard failure. this switch is off by default. In off state the APIs will continue to swallow exceptions and return an empty string. Added unit tests. * PR comments. * Throwing exception for QueryGetData also.
KlausLoeffelmann
approved these changes
Sep 3, 2026
KlausLoeffelmann
left a comment
Member
There was a problem hiding this comment.
Same remarks as stated in #15037.
Thanks, Shyam!!
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.
Backport of #15022 to release/11.0
Fixes empty string scenario in bug #14322
Description
Until .NET 9.0, the WPF Clipboard Get* APIs threw exceptions when an operation failed. This differed from the WinForms Clipboard APIs, which swallow exceptions and return an empty string.
In .NET 10, we unified the clipboard implementation in System.Private.Windows.Core. The unified implementation follows the existing WinForms behavior, but this introduces a behavior change for WPF: its Clipboard APIs now also swallow exceptions and return an empty string instead of propagating the exception.
Customer Impact
This behavior change is causing issues for some existing WPF applications that rely on exceptions being thrown to detect clipboard operation failures. More details are available in the bug.
Regression
Yes - In WPF from .NET 9.0
Fix
Added a new AppContext switch: "Windows.Clipboard.ThrowExceptionsForGetAPIs" When set, the Clipboard Get* APIs will throw exception during a Clipboard failure. This switch is off by default. In off state the APIs will continue to swallow exceptions and return an empty string.
Added unit tests.
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 empty string very frequently. After fix and with the new AppContext switch turned on, the app did not return empty string for Get* APIs at all.
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