You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restore WPF Clipboard compatibility and native EMF support in .NET 10 - #12003
This change restores established .NET 9 behavior for WPF Clipboard APIs after the move to the shared OLE implementation in System.Private.Windows.Core. It also adds comprehensive compatibility coverage for the public Clipboard APIs and restores native enhanced-metafile support.
Compatibility fixes
Return an OLE-backed data object from Clipboard.GetDataObject() so Windows-generated formats and delayed rendering remain observable.
Restore native format checks for Contains*, including MTA-safe behavior and Windows-synthesized formats.
Restore ANSI Text to UnicodeText Clipboard conversion.
Restore WPF-specific BitmapSource format mappings without exposing them from WinForms.
Preserve existing Clear, Flush, IsCurrent, and SetDataObject ownership semantics.
Retry transient CLIPBRD_E_CANT_OPEN failures when retrieving platform-specific bitmap and EMF data.
Enhanced metafile support
Opt WPF into native TYMED_ENHMF rendering and retrieval.
Support both Metafile and stream-backed EMF payloads.
Correctly assign native EMF handles to returned STGMEDIUM values.
Copy native handles before releasing the source medium.
Preserve caller ownership and source-object validity.
Support delayed rendering, Flush, and copy: true.
Return independently disposable results from repeated retrievals.
Reject WMF payloads incorrectly published as enhanced metafiles.
Restore mapped-format auto-conversion behavior.
Test coverage
The branch adds exhaustive coverage for:
Threading and apartment-state behavior.
Argument validation and exception contracts.
Text, audio, file-drop, bitmap, custom-format, and managed-object data.
Windows-generated and managed format conversion.
Clipboard ownership, replacement, persistence, and retries.
Legacy and typed Clipboard APIs.
Native EMF rendering, retrieval, mapping, streams, ownership, and disposal.
Use the OLE proxy and native format availability checks to restore
Windows-generated formats, MTA-safe Contains APIs, and legacy
BitmapSource mappings.
Add native enhanced-metafile rendering and retrieval with correct handle
ownership, transient clipboard retries, and comprehensive compatibility
tests.
Note: Build failures in this PR are expected as they need updated version of Microsoft.Private.WinForms NuGet package which will be available after corresponding WinForms PR gets merged.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This remains an intentional open dependency: the corresponding dotnet/winforms changes must be merged, published in Microsoft.Private.Winforms, and flowed into this PR before merge. No WPF-only source change can satisfy this dependency.
This coverage summary contradicts the tests added in this PR: the ANSI synthesis and GetText conversion tests use the live default copy: false object, and Contains* APIs are explicitly verified as MTA-safe rather than STA-only. Update these bullets so the documentation does not describe the regressions that this change restores.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Update the coverage summary to reflect live OLE-proxy text conversion and MTA-safe Contains APIs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f02ed50a-b99c-49d8-af4c-55b817a5fc61
Addressed the latest review summary in 46f726e. The coverage section now documents live default copy:false ANSI-to-Unicode synthesis, OLE-proxy GetText conversion, and the intentional split between STA-only OLE-backed APIs and MTA-safe Contains* checks.
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
draftPRmetadata: Label to tag PRs, to facilitate with triage
2 participants
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
Fixes #11986
Summary
This change restores established .NET 9 behavior for WPF Clipboard APIs after the move to the shared OLE implementation in
System.Private.Windows.Core. It also adds comprehensive compatibility coverage for the public Clipboard APIs and restores native enhanced-metafile support.Compatibility fixes
Clipboard.GetDataObject()so Windows-generated formats and delayed rendering remain observable.Contains*, including MTA-safe behavior and Windows-synthesized formats.TexttoUnicodeTextClipboard conversion.BitmapSourceformat mappings without exposing them from WinForms.Clear,Flush,IsCurrent, andSetDataObjectownership semantics.CLIPBRD_E_CANT_OPENfailures when retrieving platform-specific bitmap and EMF data.Enhanced metafile support
TYMED_ENHMFrendering and retrieval.Metafileand stream-backed EMF payloads.STGMEDIUMvalues.Flush, andcopy: true.Test coverage
The branch adds exhaustive coverage for:
Final validation:
PresentationCore.Tests: 1,003 passed, 29 intentional skips, 0 failed.Dependency
This requires the corresponding
System.Private.Windows.Corechanges fromdotnet/winforms, including:IDataObjectretry handling.For these changes we will need to update this PR with an updated version of
Microsoft.Private.WinFormspackage once it is available.Microsoft Reviewers: Open in CodeFlow