c# - Serialize List of objects fails with NullReferenceException -


in order support copy/paste in application, have make objects serializable able put them clipboard , them again there. works expected long there no list<xy> objects have serialized.

this first part on 1 object:

[serializable] public class parameter : gobserversubject, iserializable, iobserver {      #region attributes     private static readonly ilog log = logmanager.getlogger(typeof(parameter));     private int priority;     private string name;     private int id;     private string description;     private string comments;     private list<value> values;     private container mycontainer;     private bool changed;     private int order;     private bool noupdate;     #endregion } 

i implemented 2 methods:

public virtual void getobjectdata(serializationinfo info, streamingcontext context) {     info.addvalue("priority", priority);     info.addvalue("name", name);     info.addvalue("id", id);     info.addvalue("changed", true);     info.addvalue("order", order);     info.addvalue("values", values, values.gettype()); }  protected parameter(serializationinfo info, streamingcontext context) {     priority = info.getint32("priority");     name = info.getstring("name");     id = info.getint32("id");     values = (list<value>)info.getvalue("values", values.gettype());     changed = info.getboolean("changed");     order = info.getint32("order"); } 

this how copy , paste stuff treeview:

parameter parameter = ((treenodeparameter)this.testdesigntree.selectednode).getparameter(); clipboard.setdataobject(parameter);  idataobject idata = clipboard.getdataobject(); object copiedobject = idata.getdata(dataformats.serializable); log.info("type of selectednode is: " + this.testdesigntree.selectednode.gettype()); log.info("type of object in clipboard is: " + copiedobject.gettype()); 

the application crashes @ copiedobject.gettype() nullreferenceexception.

what doing wrong here?

seems problem how defined type of object:

values.gettype() 

should be:

typeof(list<value>); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -