question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The return value of method Clipboard.GetImage() is null in the .NET Core 3.0 winforms application

See original GitHub issue

OS: 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:

  1. Create a Winforms .Net Core application by command: dotnet new winforms –o “xxx”
  2. 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();
  3. Debug the application (\\mlangfs1\public\Winforms\v-jiaol\bug\MetaFileIssue.zip)

Actual: When debugging to actual = Clipboard.GetImage(), the result of actual is null. metafileissue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
weltkantecommented, Jul 3, 2019

I’d expect SetImage to throw an exception (unless you want to support write-only semantics for metafiles), ContainsImage return false and GetImage return null (to be consistent with other Get-methods when no data of the appropriate format is present)

Current behavior:

  • SetImage with a metafile succeeds
  • ContainsImage returns true
  • GetImage returns null

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.

0reactions
asklarcommented, Apr 5, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found