devxlogo

Retrieving Custom Objects Added to the Clipboard

Retrieving Custom Objects Added to the Clipboard

You may have found that sometimes, copying a custom .NET object to the clipboard doesn’t work. That’s because retrieving a custom object from the clipboard returns nothing if the object has a reference to a nonserializable object. The clipboard is using serialization to return a copy of the object. The object is added to the clipboard without any errors. The object shows present, but this comes back as nothing.

Most times, the offending item in the object is obvious. However, because the serialization also includes public events, any other object that is listening for an event raised by the object is included in the serialization. If any of those objects is not serializable then it fails!

The easiest way around this is to implement the Iserializable interface for your object. The serializable interface lets you decide which items of your object are serialized. You can then avoid any that might refer to other nonserializable objects?like events. Remember that an object implementing the Iserializable interface must create a special constructor. Deserializing fails if this constructor is not implemented. The interface does not automatically generate the constructor.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist