Repository navigation
[main] Restore WPF clipboard text auto conversion for managed data objects - #12124
Open
Shyam-Gupta wants to merge 4 commits into
Open
Shyam-Gupta wants to merge 4 commits into
Shyam-Gupta wants to merge 4 commits into
Conversation
Preserve Windows plain-text synthesis while retaining in-process custom payloads and legacy IDataObject retrieval. Add clipboard conversion regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 918733ee-3532-46a0-92bb-728aaa5bb200 (cherry picked from commit ff095a9)
Report wrapped typed-retrieval support and cover native typed text reads plus .NET 9-style getter forwarding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 918733ee-3532-46a0-92bb-728aaa5bb200 (cherry picked from commit 68ce741)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e32c8108-e372-40cb-9809-70f4745be462
This was referenced Nov 12, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
PresentationCore cannot compile against the pinned Microsoft.Private.Winforms dependency because it lacks the newly used APIs, so the dependency update containing dotnet/winforms#15413 is needed.
1 open issue
What changed in this PR
Ports the clipboard text-conversion fix to main to address #11968, restoring native text synthesis while preserving managed payload identity and legacy IDataObject compatibility.
Changes:
- Enables native fallback for Text, UnicodeText, and OEMText, with availability based on published clipboard formats.
- Preserves legacy retrieval through composed data objects.
- Adds regression coverage for synthesis, flushing, typed retrieval, and custom payloads.
| File | Description |
|---|---|
src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/ClipboardTests.cs |
Updates text-conversion expectations to require clipboard synthesis. |
src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/ClipboardTextConversionTests.cs |
Adds synthesis and compatibility regression tests. |
src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsOther.cs |
Adds native clipboard-format availability interop. |
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ole/WpfOleServices.cs |
Enables WPF’s native text fallback. |
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ole/DataObjectAdapter.cs |
Exposes whether the managed source supports typed retrieval. |
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs |
Composes managed data with the captured native fallback. |
src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs |
Preserves legacy getters and queries native text availability. |
Review effort: Balanced
Comment on lines
+42
to
+43
| static DataObject IDataObjectInternal<DataObject, IDataObject>.Create(DataObject clipboardData, IDataObject managedData) => | ||
| new(clipboardData._innerData.WithManagedDataObject(managedData as IDataObjectInternal ?? new DataObjectAdapter(managedData))); |
Implement the shared-core capability contract without adding public API, so the property no longer depends on a modern .NET default interface implementation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e32c8108-e372-40cb-9809-70f4745be462
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 #11968
Main PR: this PR targets
main.Release/11.0 companion port: #12125.
Description
Port the changes proposed in #12105 (targeting
release/10.0) tomain, including both source commits (ff095a98e,68ce741d9) with cherry-pick provenance. Normalize the added test file's encoding and explicitly implementIDataObjectInternal.SupportsTypedDataonDataObjectto match the companion's required capability contract. That capability declaration adds no public API.Restores Windows clipboard text synthesis for WPF after the .NET 10 shared-OLE migration. Opts into a captured native fallback for Text, UnicodeText, and OEMText while preserving managed custom-payload identity, published-format availability, and legacy IDataObject compatibility.
WPF explicitly sets
UseNativeClipboardTextFallback => true: fallback is enabled for WPF by this PR. The shared-core policy's defaultfalseapplies to consumers that do not opt in, not to WPF. WinForms explicitly sets the policy tofalse.Plain-text
ContainsText/ContainsDatachecks query Windows' published clipboard formats directly, including native synthesis; later mutations of a managed source do not count as newly published formats. Convenience getters remain usable with legacy-onlyIDataObjectsources. Composed wrappers forward single-argument string getters through theautoConvert: trueoverloads, matching .NET 9 wrapper dispatch.Requires the corresponding shared-core WinForms port, dotnet/winforms#15413, and an updated
Microsoft.Private.Winformsdependency containing it. The dependency update is not included in this port; integration validation remains required after that package is available.The companion also supports opt-in fallback in its Framework-targeted shared-core library. This WPF PR targets modern .NET; it does not change the installed .NET Framework WPF product.
Customer Impact
Applications publishing ANSI text can receive false from
Clipboard.ContainsText()or empty text fromClipboard.GetText(), breaking workflows that worked in .NET 9.Regression
Yes. Fixes a .NET 10 regression in clipboard text conversion.
Testing
Local validation below was recorded on 2026-11-12. The WPF build attempt preceded the final explicit-capability declaration; no successful WPF build or test run against the matching new shared-core package is recorded. No tests were rerun for this description-only audit.
.\build.cmd -projects src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\PresentationCore.Tests.csproj -platform x64 -msbuildEngine vs- failed before test execution: native-tool bootstrap failed (Perl, .NET Framework reference assemblies, and Windows SDK redist unavailable); the build also reported missing PresentationBuildTasks references and API compatibility contracts. No WPF test pass is claimed..\.dotnet\dotnet.exe format whitespace src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\PresentationCore.Tests.csproj --no-restore --verify-no-changes --include src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\ClipboardTextConversionTests.cs- passed, with workspace-loading warnings..\.dotnet\dotnet.exe format whitespace src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\PresentationCore.Tests.csproj --no-restore --verify-no-changes --include src\Microsoft.DotNet.Wpf\src\PresentationCore\System\Windows\DataObject.cs- passed after the explicit-capability cleanup, with workspace-loading warnings. WPF build/integration validation remains blocked as described above; the build was not retried for this cleanup.System\Windows\ClipboardTests.cs:118-119, outside the port's changed lines; left unchanged.git diff --check origin/main- passed.31cf87a1e: 107 modern shared-core, 110 .NET Framework (including 21 fallback cases), and 6 WinForms clipboard regression cases passed; exact commands/results are in [main] Add opt-in native clipboard text fallback for WPF winforms#15413. Of the fallback cases, 17 run on both targets and 4 specifically exercise Framework managed-COM recovery and instance dispatch. Shared-core tests use mock clipboard services; these results do not substitute for WPF integration testing.Risk
Moderate. WPF explicitly opts in and WinForms explicitly opts out. Native fallback is limited to the three plain-text formats, but composed wrappers also change single-argument string-getter dispatch for other formats. Custom-payload retrieval, enumeration, and writes stay on the managed source. WPF availability checks are case-insensitive; the companion's fallback selection uses exact-case format names. WPF integration has not been validated locally because of the build prerequisites and pending shared-core package update; this is not a standalone fix without that dependency.