Skip to content

[release/11.0] Fix providing EnhancedMetafile to other applications through the clipboard - #12059

Open
Shyam-Gupta wants to merge 1 commit into
release/11.0from
dev/shgu/port11988_11.0
Open

Shyam-Gupta wants to merge 1 commit into
release/11.0from
dev/shgu/port11988_11.0

Conversation

@Shyam-Gupta

@Shyam-Gupta Shyam-Gupta commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #11986

Depends on corresponding WinForms side of changes: dotnet/winforms#15328
This PR has to merge before that change flows into WPF, or WPF won't build.

Description

On .NET 10, the shared OLE code in System.Private.Windows.Core rejects every TYMED_ENHMF request with DV_E_TYMED, so WPF can't provide CF_ENHMETAFILE to other applications even though the format is still advertised.

  • Add WpfOleServices.AllowedTymeds, which also allows TYMED_ENHMF. It implements the new IOleServices.AllowedTymeds from dotnet/winforms#TBD.
  • Fix the TYMED_ENHMF branch of WpfOleServices.GetDataHere, which was unreachable until now. For a MemoryStream it never assigned the handle to the medium, so it returned S_OK with a null handle. It now sets tymed and hEnhMetaFile, and returns E_FAIL when there is no handle, as .NET 9 did.
  • Add a clipboard test that reads the EMF back with GetClipboardData, the way another application would. It's skipped until the winforms change flows in.

I'd like to request a backport to release/10.0 after this merges.

Customer Impact

EMF that WPF apps put on the clipboard can't be pasted into other applications, for example Word's Paste Special → Picture (Enhanced Metafile). It fails silently, and there's no workaround.

Regression

Yes. It works on .NET 9 and is broken on .NET 10.

Testing

Risk

Low. It only affects TYMED_ENHMF requests for EnhancedMetafile data, which always fail today, and restores the .NET 9 behavior.

Microsoft Reviewers: Open in CodeFlow

…board

The shared OLE code in System.Private.Windows.Core only accepts
TYMED_HGLOBAL, TYMED_ISTREAM and TYMED_GDI, so every request for
CF_ENHMETAFILE (always TYMED_ENHMF) fails before WPF's handler runs.

- Add WpfOleServices.AllowedTymeds, which also allows TYMED_ENHMF. It
  implements IOleServices.AllowedTymeds once the companion
  dotnet/winforms change flows in, and must be in place before then.
- Fix the TYMED_ENHMF branch of WpfOleServices.GetDataHere, which never
  assigned the handle created from a MemoryStream and returned S_OK with
  a null handle. It now sets tymed and hEnhMetaFile, and returns E_FAIL
  when there is no handle, as .NET 9 did.
- Add a clipboard test that reads the EMF back the way another
  application would. It is skipped until the winforms change flows in.

Fixes #11986

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Backport-of: #11988
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0894b2bd-53a0-4ca6-ad0c-b04194aff537
@Shyam-Gupta Shyam-Gupta self-assigned this Oct 28, 2026
@Shyam-Gupta Shyam-Gupta added Servicing-consider area-clipboard Issues related to DataObject and shared clipboard labels Oct 28, 2026
@Shyam-Gupta
Shyam-Gupta requested a review from a team October 28, 2026 17:30
@Shyam-Gupta
Shyam-Gupta requested a review from a team as a code owner October 28, 2026 17:30
@Shyam-Gupta Shyam-Gupta changed the title Fix providing EnhancedMetafile to other applications through the clipboard [release/11.0] Fix providing EnhancedMetafile to other applications through the clipboard Oct 28, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hi @Shyam-Gupta. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@dotnet-policy-service dotnet-policy-service Bot added the PR metadata: Label to tag PRs, to facilitate with triage label Oct 28, 2026

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

LGTM

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

Labels

area-clipboard Issues related to DataObject and shared clipboard PR metadata: Label to tag PRs, to facilitate with triage Servicing-consider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants