[release/10.0] AppContext switch for restoring exception handling behavior in WPF Clipboard APIs - #15037
Conversation
…ipboard APIs (dotnet#15022) * Fixes empty string scenario in bug dotnet#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.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/10.0 #15037 +/- ##
======================================================
- Coverage 77.11050% 77.10708% -0.00343%
======================================================
Files 3274 3274
Lines 645095 645169 +74
Branches 47709 47715 +6
======================================================
+ Hits 497436 497471 +35
- Misses 143976 144013 +37
- Partials 3683 3685 +2
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
I would say, OK.
2 Question though, which we can iterate too, if we do not have good answers for it:
-
When we tweak the behavior now for WPF - does that have any side effects on how the WinForms clipboard used to handle corner cases? (Or usual cases?)
-
If we change clipboard behavior with a context switch - what effects does that context switch have for a scenario, where a WPF App hosts a WinForms UserControl with a WinForms host control, or a WinForms Apps hosts a WPF UserControl with the ElemementHost.
(We do not need to address this now - and do this iteratively, to unblock customers as quick as possible. But let's also make sure, we're not introducing issues "for the other side" at the same time.)
The default behavior of the WinForms Clipboard APIs will remain the same. The Get* APIs don't throw exceptions for .NET 9 and previous versions, and they will continue in the same manner going forward. Only when the new AppContext switch is turned on, the APIs will throw exception.
The AppContext switch is at app level. If it is turned on for a WPF or WinForms app, the Get* APIs will start throwing exceptions. |
|
Approved over email. |
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. Note that it still returns empty string if QueryGet* API fails which have same behavior as in .NET 9.
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