开发者

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

开发者 https://www.devze.com 2023-01-06 04:36 出处:网络
I am working with the clipboard in .net with the following code List<object> templateList = new List<object>();

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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消