c# - Message serialized with XmlMessageFormater refuses to deserialize List<T> member -
i'm having frustrating time c# message serialization. have class has constructor looks this:
public proposalrequestmessage(int imanumber, int proposalid, bool trainingflag, string firstsiteaddress, bool lastsiteflag, string lastsiteaddress, int reasoncode, list<laneselection> thelaneselections) { imanumber = imanumber; proposalid = proposalid; trainingflag = trainingflag; firstsiteaddress = firstsiteaddress; lastsiteflag = lastsiteflag; lastsiteaddress = lastsiteaddress; reasoncode = reasoncode; laneselections = new list<laneselection>(thelaneselections); } the lanesselections fellow member of class of of type system.collections.generic.list, laneselection looks this:
public class laneselection { public int laneid { get; set; } public signalaspect aspectcode { get; set; } public laneselection() { } public laneselection(int laneid, signalaspect aspectcode) { laneid = laneid; aspectcode = aspectcode; } } a signalaspect enumeration.
i send message containing instance of class on msmq follows:
system.messaging.messagequeue queue = new system.messaging.messagequeue(queuename); queue.purge(); system.messaging.message msg = new system.messaging.message(themessage, new system.messaging.xmlmessageformatter()); queue.send(msg); using debug tools, have found resulting xml looks bit this:
<?xml version="1.0"?> <ivtmmessage xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <messagetype>proposalrequest</messagetype> <proposalrequestmessage> <imanumber>0</imanumber> <proposalid>2</proposalid> <trainingflag>false</trainingflag> <firstsiteaddress>m25/4690a</firstsiteaddress> <lastsiteflag>false</lastsiteflag> <lastsiteaddress /> <reasoncode>3</reasoncode> <laneselections> <laneselection> <laneid>1</laneid> <aspectcode>advisory20</aspectcode> </laneselection> </laneselections> </proposalrequestmessage> i deserialize message @ other end so:
queue = new system.messaging.messagequeue(queuename); queue.formatter = new system.messaging.xmlmessageformatter(new type[] { typeof(ivtmmessage) }); queue.receivecompleted += new system.messaging.receivecompletedeventhandler(queue_receivecompleted); queue.beginreceive(new system.timespan(0, 0, 0, 30)); ... system.messaging.messagequeue mq = (system.messaging.messagequeue)sender; seek { // end asynchronous receive operation. system.messaging.message m = mq.endreceive(e.asyncresult); ivtmmessage message = (ivtmmessage)m.body; decodemessage(message); } grab (system.messaging.messagequeueexception ex) { string exception = ex.message; } mq.beginreceive(); return; every fellow member of class correctly deserialized except laneselections element which, although has value in xml, evaluates null instances in deserialized message.
in deseparation tried adding list class, populating values 1-5 on construction. if serialized correctly show me problem laneselection class, if not issue serializing list. list did not serialize correctly.
does know what's going wrong?
two things;
there "laneselections" in ivtmmessage declaration serialized xml "laneselections" capital l. xml serialization/deserialization case sensitive , caught me out more once have tried adding next laneselections property of ivtmmessage class in code below;property definition;
[xmlarray("laneselections"), xmlarrayelement("laneselection")] public list<laneselection> laneselections { get; set; } without proper xml attributes on properties , classes you're leaving serializer interpret how properties/objects should translated
c# deserialization msmq xml-deserialization
No comments:
Post a Comment