Data Placed on Clipboard from Windows Forms Application Unavailable


You have developed an application using the Microsoft .Net Framework 4.0. The application creates a new System.Windows.Forms.DataObject using an unregistered clipboard format, and then calls the System.Windows.Forms.Clipboard.SetDataObject method to place the custom DataObject on the Windows Clipboard. On an intermittent basis, applications are unable to retrieve the contents of this custom IDataObject from the Clipboard. For example, calling System.Windows.Forms.Clipboard.GetDataObject using the specified clipboard format returns null, instead of the expected System.Windows.Forms.DataObject previously placed on the Clipboard.


This is due to a bug in the Microsoft .Net Framework 4.0.


This bug has been corrected in the Microsoft .Net Framework 4.5.

More Information

The Windows operating system registers Clipboard format ID's as unsigned 16-bit integers with the leading bit set. In Microsoft .Net Framework 4.0, the Windows Forms implementation caches the Format ID's in an internal list as signed 32-bit integers. When an application calls into the Windows Forms IDataObject::GetData method to retrieve an IDataObject for a specified format, Windows Forms iterates over its internal list comparing the requested format ID (as an unsigned16-bit integer) with the cached format ID (stored as a 32-bit signed integer). Without the proper casts, the comparison fails and the expected Format is not returned. This eventually leads to the Windows Forms IDataObject::GetData returning null to the caller.

ID d'article : 2843635 - Dernière mise à jour : 8 mai 2013 - Révision : 1