Skip to content

[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
release/11.0from
backport/pr-15022-to-release/11.0
Open

[release/11.0] AppContext switch for restoring exception handling behavior in WPF Clipboard APIs#15035
github-actions[bot] wants to merge 1 commit into
release/11.0from
backport/pr-15022-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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

…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.
@github-actions
github-actions Bot requested a review from a team as a code owner September 3, 2026 18:30
@Shyam-Gupta Shyam-Gupta self-assigned this Sep 3, 2026
@Shyam-Gupta Shyam-Gupta added the area-Clipboard Issues related to Clipboard label Sep 3, 2026

@KlausLoeffelmann KlausLoeffelmann 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.

Same remarks as stated in #15037.

Thanks, Shyam!!

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

Labels

area-Clipboard Issues related to Clipboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants