Skip to content

[release/10.0] Add opt-in native clipboard text fallback for WPF - #15370

Merged
Shyam-Gupta merged 2 commits into
release/10.0from
dev/shgu/bug11968_10.0
Nov 17, 2026
Merged

Shyam-Gupta merged 2 commits into
release/10.0from
dev/shgu/bug11968_10.0

Conversation

@Shyam-Gupta

@Shyam-Gupta Shyam-Gupta commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Fixes dotnet/wpf#11968 in conjunction with the corresponding WPF changes.

Proposed changes

  • Add an internal, default-disabled policy allowing WPF to opt into native clipboard text fallback. WinForms explicitly remains opted out.
  • Combine the original managed source with a captured native OLE reader. Read from the managed source first, then use the native reader if needed for Text, UnicodeText, and OEMText. For sources that don't support typed reads, typed text reads go straight to the native reader.
  • For composed clipboard wrappers, forward single-argument GetData and GetDataPresent calls to the overloads with autoConvert: true, matching .NET 9. This also applies to non-text formats, but native fallback is still limited to plain text.
  • Preserve custom-payload identity, managed format enumeration, and writes. Add six regression cases covering WinForms clipboard behavior before and after flushing.

Customer Impact

  • Enables WPF to restore Windows text synthesis when managed clipboard sources disable automatic conversion, addressing missing text availability and retrieval reported in Regression in Clipboard/DataObject text conversion wpf#11968.
  • Preserves existing WinForms behavior: unflushed clipboard data retains managed conversion semantics, while flushed data exposes Windows-synthesized formats.

Regression?

  • Yes - supports fixing a .NET 10 WPF regression. No intentional WinForms behavior change.

Risk

  • Low for WinForms because the fallback policy remains disabled. Moderate for opted-in consumers because shared clipboard composition and retrieval paths change. Native fallback is limited to plain-text formats and keeps the captured proxy's owning adapters alive.

Test methodology

  • Automated test execution and CTI manual validation.
Microsoft Reviewers: Open in CodeFlow

Compose managed clipboard sources with a captured native text reader while preserving custom payload identity. Keep WinForms clipboard behavior unchanged and add regression coverage.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 918733ee-3532-46a0-92bb-728aaa5bb200
@Shyam-Gupta Shyam-Gupta self-assigned this Nov 5, 2026
@Shyam-Gupta
Shyam-Gupta requested a balanced review from Copilot November 5, 2026 22:20
@dotnet-policy-service dotnet-policy-service Bot added the draft draft PR label Nov 5, 2026

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.

🟡 Changes recommended

The composed clipboard path can fail valid legacy text reads, bypass application overloads, and mishandle format-name casing, while the new fallback path lacks direct test coverage.

4 open issues
What changed in this PR

Adds an internal, opt-in native clipboard text fallback to support the WPF text-conversion regression fix while keeping WinForms opted out.

Changes:

  • Introduces a default-disabled policy for native Text, UnicodeText, and OEMText fallback.
  • Combines managed-first retrieval with a captured native clipboard reader.
  • Adds six WinForms regression cases covering flushed and unflushed text behavior.
File Description
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​ClipboardTextConversionTests.cs Adds text-conversion regression cases.
src/​System.Windows.Forms/​System/​Windows/​Forms/​OLE/​WinFormsOleServices.cs Explicitly disables fallback for WinForms.
src/​System.Windows.Forms/​System/​Windows/​Forms/​OLE/​DataObject.cs Adds construction from a composed clipboard view.
src/​System.Private.Windows.Core/​tests/​System.Private.Windows.Core.Tests/​System/​Private/​Windows/​Ole/​TestDataObject.cs Implements the composition factory for test objects.
src/​System.Private.Windows.Core/​src/​System/​Private/​Windows/​Ole/​IOleServices.cs Defines the default-disabled fallback policy.
src/​System.Private.Windows.Core/​src/​System/​Private/​Windows/​Ole/​IDataObjectInternal.cs Adds the managed/native composition factory contract.
src/​System.Private.Windows.Core/​src/​System/​Private/​Windows/​Ole/​Composition.cs Adds managed-first legacy and typed text fallback.
src/​System.Private.Windows.Core/​src/​System/​Private/​Windows/​Ole/​ClipboardCore.cs Creates composed clipboard results for opted-in consumers.

Review effort: Balanced

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.17660%. Comparing base (f3adc27) to head (5fb8ee6).
⚠️ Report is 24 commits behind head on release/10.0.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           release/10.0      #15370         +/-   ##
======================================================
+ Coverage      77.10831%   77.17660%   +0.06828%     
======================================================
  Files              3275        3278          +3     
  Lines            645221      645377        +156     
  Branches          47716       47737         +21     
======================================================
+ Hits             497519      498080        +561     
+ Misses           144023      143606        -417     
- Partials           3679        3691         +12     
Flag Coverage Δ
Debug 77.17660% <95.74468%> (+0.06828%) ⬆️
integration 18.99661% <25.71429%> (+0.01867%) ⬆️
production 52.07872% <94.28571%> (+0.15376%) ⬆️
test 97.41013% <100.00000%> (+0.00082%) ⬆️
unit 49.53170% <94.28571%> (+0.18157%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Route legacy-only plain-text requests through the captured native typed reader without invoking legacy getters. Add opt-in fallback tests covering .NET 9-compatible casing and dispatch, captured-reader retention, and managed payload behavior.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 918733ee-3532-46a0-92bb-728aaa5bb200

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.

🔵 Needs a closer look

Mock-based tests cannot establish native text synthesis or captured OLE-proxy lifetime after clipboard replacement, so Windows integration validation with the matching WPF/package pair is needed.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

@Shyam-Gupta Shyam-Gupta added the area-Clipboard Issues related to Clipboard label Nov 11, 2026
@Shyam-Gupta
Shyam-Gupta marked this pull request as ready for review November 11, 2026 23:59
@Shyam-Gupta
Shyam-Gupta requested a review from a team as a code owner November 11, 2026 23:59
@dotnet-policy-service dotnet-policy-service Bot removed the draft draft PR label Nov 12, 2026
@Shyam-Gupta Shyam-Gupta added the servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria label Nov 13, 2026
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

Approved over email.

@Shyam-Gupta Shyam-Gupta added servicing-approved .NET Shiproom approved the PR for merge and removed servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Nov 17, 2026
@Shyam-Gupta
Shyam-Gupta merged commit 7b7bc3b into release/10.0 Nov 17, 2026
9 checks passed
@Shyam-Gupta
Shyam-Gupta deleted the dev/shgu/bug11968_10.0 branch November 17, 2026 22:44
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 servicing-approved .NET Shiproom approved the PR for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants