xml - C# Deserialisation List Count Zero -


having trouble getting classes deserialise correctly.

the other deserialisation classes working fine , appear similar in nature when deserialiser runs, 0 count both errordetail , string lists.

what have missed/done wrong?

xml:

<placeorderresponse     xmlns="http://blah.co.uk">     <placeorderresult         xmlns:a="http://blah.co.uk/webservicemessage"         xmlns:i="http://www.w3.org/2001/xmlschema-instance">         <a:errordetails             xmlns:b="http://blah.co.uk/error">             <b:errordetail>                 <b:code>1fasd</b:code>                 <b:message>explain</b:message>             </b:errordetail>         </a:errordetails>         <a:id i:nil="true"/>         <a:informationalmessages             xmlns:b="http://schemas.microsoft.com/2003/10/serialization/arrays"/>             <a:status>1</a:status>         </placeorderresult>     </placeorderresponse> 

c# classes:

[serializable()]     [xmlroot(elementname = "placeorderresponse", namespace = "http://blah.co.uk", isnullable = false)]     [xmltype(anonymoustype = true, namespace = "http://blah.co.uk")]     public class placeorderresponse     {         [xmlelement(elementname = "placeorderresult")]         public placeorderresult placeorderresult { get; set; }     }      [xmlroot(elementname = "placeorderresult")]     public class placeorderresult : webservicemessage { }  [xmlroot(namespace = "http://blah.co.uk/webservicemessage")]     [xmltype(anonymoustype = true)]     public class webservicemessage     {         [xmlarray("errordetails")]         [xmlarrayitem("errordetail", typeof(errordetail))]         public errordetails errordetails { get; set; }         [xmlelement("id")]         public string id { get; set; }         [xmlarray("informationmessages")]         [xmlarrayitem(typeof(string))]         public list<string> informationmessages { get; set; }         [xmlelement("status")]         public string status { get; set; }     }  [xmlroot(elementname = "errordetails")]     [xmltypeattribute(anonymoustype = true)]     public class errordetails : list<errordetail> { }      [xmlroot(elementname = "errordetail", namespace = "http://blah.co.uk/error")]     [xmltypeattribute(anonymoustype = true)]     public class errordetail     {         [xmlelement(elementname = "code")]         public string code { get; set; }         [xmlelement(elementname = "message")]         public string message { get; set; }     } 

your xmlarrayitem inherit namespace parent. need explicitly include this:

[xmlarrayitem("errordetail", typeof(errordetail), namespace = "http://blah.co.uk/error")]. 

regarding informational messages, there no strings load it's hard tell xml should like. expect elements of form <string>message</string>

as tip, easiest way debug these issues try reverse - create object , serialize xml. compare trying deserlialize , you'll find quite easy spot differences lie.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -