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.

Clipboard.ContainsImage inconsistent with Clipboard.GetImage

See original GitHub issue

In #493 it was decided that removing metafile support from Clipboard.GetImage is by design. However Clipboard.SetImage and Clipboard.ContainsImage were never adjusted and still support metafiles, this leads to an inconsistent API.

Clipboard.SetImage(new Metafile("example.emf")); // copies the metafile to the clipboard
Clipboard.ContainsImage(); // returns true
Clipboard.GetImage(); // returns null by design, issue #493
  • GetImage returning null (instead of throwing an exception) is correct, since all clipboard APIs return null if there is no compatible data available. Since #493 removes compatibility for reading metafiles this is expected behavior.
  • ContainsImage returning true if a metafile is present is a bug, it must return false because GetImage will not be able to read the metafile.
  • SetImage still supports metafiles so we now have a write-only API which is arguably not a bug, but it may be confusing why you can write metafiles but not read them back. If you want to drop support for metafiles from SetImage as well then it should throw an exception.

Side note: I didn’t test it explicitely but I assume the DataObject APIs behave the same way as the Clipboard APIs and need the same fix.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
merriemcgawcommented, Jan 11, 2023

I’d like @JeremyKuhne and @lonitra to factor this into their research and planning for resources and clipboard moving forward. BinaryFormatter deprecation and how we decide to handle that might open up some options here.

1reaction
weltkantecommented, Apr 6, 2020

Not at all, will create a separate PR for the DataObject changes not directly related to the process crash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is Clipboard.ContainsImage() reliable or even useful?
It is more performant than calling GetImage() , therefore its worth doing even though in a small % of cases GetImage() will fail?...
Read more >
Clipboard.GetImage() returns null when ...
Developer Community. For unknown reason, Clipboard. GetImage() returns null even if there is a bitmap in the clipboard.
Read more >
[Solved] Clipboard and External Images
But the same image copied to the clipboard outside the app returns a null with Clipboard.GetImage() as well as false from ContainsImage().
Read more >
Clipboard.ContainsImage Method (System.Windows.Forms)
Indicates whether there is data on the Clipboard that is in the Bitmap format or can be converted to that format.
Read more >
Wrestling with Clipboard Images in WPF - Rick Strahl's Web Log
Getting images from the clipboard correctly in WPF - or heck in general in Windows - is hard if you need it to...
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