The return value of method Clipboard.GetImage() is null in the .NET Core 3.0 winforms application
See original GitHub issueOS: RS3 X64 VS: Visual Studio 2019 Version 16.0.0.0 Preview 4.0 [28625.133.d16.0] .NET SDK: .NET Core 3.0 3.0.100-preview4-10523 from master branch
More Info: In .NET framework application, the return value is correct .
Steps to Reproduce:
- Create a Winforms .Net Core application by command: dotnet new winforms –o “xxx”
- Write code to Form1.cs
using System.Drawing.Imaging; Image actual = null; Metafile expected = new Metafile(@"D:\MS.emf"); Clipboard.SetImage(expected); actual = Clipboard.GetImage(); - Debug the application (\\mlangfs1\public\Winforms\v-jiaol\bug\MetaFileIssue.zip)
Actual:
When debugging to actual = Clipboard.GetImage(), the result of actual is null.

Expected:
When debugging to actual = Clipboard.GetImage(), the result of actual should be a System.Drawing.Imaging.Metafile object.

Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (15 by maintainers)
Top Results From Across the Web
c# - Clipboard is always null
The problem is that you are trying to access the clipboard from a console application but if you would try it from within...
Read more >Clipboard.GetImage() returns null when ...
GetImage() returns null even if there is a bitmap in the clipboard. Reproduction steps: Create a new WinForms project (.NET Framework 4.7.2) ...
Read more >Clipboard.GetImage Method (System.Windows.Forms)
Returns. An Image representing the Clipboard image data or null if the Clipboard does not contain any data that is in the Bitmap...
Read more >Spread Windows Forms Developer's Guide
This guide provides introductory conceptual material and how-to explanations for routine tasks for developers using. Spread Windows Forms.
Read more >Building a Clipboard History Viewer Using PowerShell
Automatically list new clipboard items as they come in; Allow for filtering to find specific items. Not a lot of requirements here, but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’d expect
SetImageto throw an exception (unless you want to support write-only semantics for metafiles),ContainsImagereturn false andGetImagereturn null (to be consistent with other Get-methods when no data of the appropriate format is present)Current behavior:
IMHO thats broken. Do you want to reopen or should I file new issues? In particular the fact that ContainsImage returns true but GetImage returning no image is going to be confusing, if metafiles are no longer supported by design then ContainsImage should return false.
@russkie @merriemcgaw Hey Merrie, could you please clarify the context for dropping support for WMF/EMF? This is a format that’s widespread and widely used (e.g. both within Windows and by Office apps). Removing this functionality seems problematic, I’d like to understand what security we are gaining from this, when the Win32 API is still available. Moreover, the current state is broken because when you enumerate the formats, metafile is in there but when you ask for it, you get back null, which is a violation of the API contract.