c# - Deserializing xml to list object returning null -


i'm trying deserialize xml data using xmlreader list object getting null call. here sample of xml data...

<exceptionlog>     <exceptionlogdata messagecount="1" sourcedatetime="2016-02-08t09:32:41.713" minsourcedatetime="2016-02-08t09:32:41.713" dataid="610029" maxexceptionlogid="610029" messagetext="invalid_session_id: invalid session id found in sessionheader: illegal session. session not found, missing session hash: hx7k7lonetilw5rfgt432g==&#xa;this expected, can happen if session has expired , swept away, or if user logs out, or if trying hack in. " machinename="vertexdportsql1" appdomainname="vtms.windows.salesforceservicingagent.exe" processname="vtms.windows.salesforceservicingagent" />     <exceptionlogdata messagecount="1" sourcedatetime="2016-02-08t09:22:39.340" minsourcedatetime="2016-02-08t09:22:39.340" dataid="610028" maxexceptionlogid="610028" messagetext="invalid_session_id: invalid session id found in sessionheader: illegal session. session not found, missing session hash: rtztrlk2f99ivttloz31tg==&#xa;this expected, can happen if session has expired , swept away, or if user logs out, or if trying hack in. " machinename="vertexdportsql1" appdomainname="vtms.windows.salesforceservicingagent.exe" processname="vtms.windows.salesforceservicingagent" /> </exceptionlog> 

this object class code trying create...

public class exceptionlog {     public exceptionlog() {         exceptionlogdata = new list<exceptionlogexceptionlogdata>();     }      public list<exceptionlogexceptionlogdata> exceptionlogdata { get; set; } }  public class exceptionlogexceptionlogdata {     private datetime _sourcedatetimefield;      private datetime _minsourcedatetimefield;      private uint dataidfield;      private uint _maxexceptionlogidfield;      private string _messagetextfield;      private string _machinenamefield;      private string _appdomainnamefield;      private string _processnamefield;      public byte messagecount { get; set; }      public datetime sourcedatetime {         {             return _sourcedatetimefield;         }         set {             _sourcedatetimefield = value;         }     }      public datetime minsourcedatetime {         {             return _minsourcedatetimefield;         }         set {             _minsourcedatetimefield = value;         }     }      public uint dataid {         {             return dataidfield;         }         set {             dataidfield = value;         }     }      public uint maxexceptionlogid {         {             return _maxexceptionlogidfield;         }         set {             _maxexceptionlogidfield = value;         }     }      public string messagetext {         {             return _messagetextfield;         }         set {             _messagetextfield = value;         }     }      public string machinename {         {             return _machinenamefield;         }         set {             _machinenamefield = value;         }     }      public string appdomainname {         {             return _appdomainnamefield;         }         set {             _appdomainnamefield = value;         }     }      public string processname {         {             return _processnamefield;         }         set {             _processnamefield = value;         }     } } 

and here how trying deserialize data...

        using (var datareader = sqlcommand.executexmlreader())         {             var serializer = new xmlserializer(typeof(exceptionlog));              var returndatalist = serializer.deserialize(datareader) list<exceptionlogexceptionlogdata>;             return returndatalist;         } 

what have missed or doing wrong?

i have approach can use until figure out , old fashioned way of creating object list , programmatically populating objects on fly - not graceful time being works.

tia

xmlserializer defined of type exceptionlog you're casting result list

var serializer = new xmlserializer(typeof(exceptionlog)); var returndatalist = serializer.deserialize(datareader) list<exceptionlogexceptionlogdata>; 

the casting should type of serializer:

var returndatalist = serializer.deserialize(datareader) exceptionlog; 

i didn't check elements should mark exceptionlogdata xmlelement attribute.

[xmlelement] public list<exceptionlogexceptionlogdata> exceptionlogdata { get; set; } 

there might issues other properties should address problem in question


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -