Kev Hunter
Kev Hunter

Reputation: 2625

Why does this object always come back from the clipboard as null

I am working with the clipboard in .net with the following code

   List<object> templateList = new List<object>();
  Clipboard.Clear();


Clipboard.SetDataObject(templateList);
   IDataObject dataObject = Clipboard.GetDataObject();
   var x = (List<object>)dataObject.GetData(typeof(List<object>));

For the above code x is an empty List of objects as you would expect

if i change the code to be

 List<Template> templateList = new List<Template>();
 Clipboard.Clear();
 Clipboard.SetDataObject(templateList);
 IDataObject dataObject = Clipboard.GetDataObject();
 var x = (List<Template>)dataObject.GetData(typeof(List<Template>));

x is now null

the class for Template is both public and Serializable and the application is running on a STAthread

Any ideas?

Upvotes: 2

Views: 333

Answers (1)

barrylloyd
barrylloyd

Reputation: 1589

Does Template have any object properties that are not marked as serializable? In other words, even though Template is marked as serializable have you actually tried to serialize it, to confirm this works?

Upvotes: 1

Related Questions