c# - Can't Serialize Dictionary with the XML Serializer -



c# - Can't Serialize Dictionary with the XML Serializer -

i have problem serializing class. made sure classes component classes public , made sure there non null values in each class variables. there reason why cant serialize this?

exceptions:

an unhandled exception of type 'system.invalidoperationexception' occurred in system.xml.dll additional information: there error reflecting type 'somenamespace.tmpclass .

below code:

public class tmpclass : icloneable { public list<string> str_pattern { get; set; } public int grouping { get; set; } public double tp { get; set; } public double sl { get; set; } public int index { get; set; } public int num { get; set; } public string direction { get; set; } public string open; public string close; public tmpclass () { open= "na"; close= "na"; direction = "na"; } public dictionary<string, someclass> stats = new dictionary<string, someclass>(); // serialize info public void save(string filename, string location) { string file = string.concat(location, filename); using (var stream = new filestream(file, filemode.create)) { xmlserializer xml = new xmlserializer(typeof(tmpclass)); xml.serialize(stream, this); } } // deserialize info public static tmpclass load(string filename, string location) { string file = string.concat(location, filename); using (var stream = new filestream(file, filemode.open)) { xmlserializer xml = new xmlserializer(typeof(tmpclass)); homecoming (tmpclass)xml.deserialize(stream); } } // public object clone() { homecoming this.memberwiseclone(); } }

here exception:

string index: 1 system.invalidoperationexception: there error reflecting type 'stringbui lder.string'. ---> system.notsupportedexception: cannot serialize fellow member patter nbuilder.string.stats of type system.collections.generic.dictionary`2[[system.s tring, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e0 89],[stringbuilder.someclass, stringbuilder, version=1.0.0.0, cultu re=neutral, publickeytoken=null]], because implements idictionary. @ system.xml.serialization.typescope.getdefaultindexer(type type, string mem berinfo) @ system.xml.serialization.typescope.getcollectionelementtype(type type, str ing memberinfo) @ system.xml.serialization.typescope.importtypedesc(type type, memberinfo me mberinfo, boolean directreference) @ system.xml.serialization.typescope.gettypedesc(type type, memberinfo sourc e, boolean directreference, boolean throwonerror) @ system.xml.serialization.structmodel.getfieldmodel(fieldinfo fieldinfo) @ system.xml.serialization.structmodel.getfieldmodel(memberinfo memberinfo) @ system.xml.serialization.xmlreflectionimporter.initializestructmembers(str uctmapping mapping, structmodel model, boolean openmodel, string typename, recur sionlimiter limiter) @ system.xml.serialization.xmlreflectionimporter.importstructlikemapping(str uctmodel model, string ns, boolean openmodel, xmlattributes a, recursionlimiter limiter) @ system.xml.serialization.xmlreflectionimporter.importtypemapping(typemodel model, string ns, importcontext context, string datatype, xmlattributes a, bool ean repeats, boolean openmodel, recursionlimiter limiter) --- end of inner exception stack trace --- @ system.xml.serialization.xmlreflectionimporter.importtypemapping(typemodel model, string ns, importcontext context, string datatype, xmlattributes a, bool ean repeats, boolean openmodel, recursionlimiter limiter) @ system.xml.serialization.xmlreflectionimporter.importelement(typemodel mod el, xmlrootattribute root, string defaultnamespace, recursionlimiter limiter) @ system.xml.serialization.xmlserializer..ctor(type type, string defaultname space) @ stringbuilder.string.save(string filename, string location) in c:\users\ wei\dropbox\work\personal\cs\stringbuilder\data.cs:line 133 @ stringbuilder.program.main(string[] args) in c:\users\wei\dropbox\work\pe rsonal\cs\stringbuilder\program.cs:line 48

c# serialization

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -