c# - Problem xml-deserializing recursive nested object -


Solution: The code below is not causing an infinite loop as I thought. Was in the loop code, which was called desiilization. This post code works fine

I am trying to serial and deserialize XML to the following object

  public class MessageObjectCollection: List & Lt; MessageObject & gt; {Public string serial ize () {XmlObjectSerializer return.SerializeObject (this); } Public Status Message Object Declaration (String Serialization Resisance) {Return XMLAllore Surveyor. Directoryal Object & lt; Message Object Colback & gt; (Serialized premium history); }}  

Message content looks like this

  public class MessageObject {public string title; Public message object selection feedback; }  

So if I have an example of messageobjectcollection that looks:

  var msgColl = New MessageObjectCollection {new MessageObject {title = "Hello", Answer = New MessageObjectCollection {new MessageObject {title = "hi", Responsive = null}}}}  

I var xml = msgColl.Serialize ();

However, when I try to deserialize it by calling var msgColl = New MessageObjectCollection (). Deserialize (xml);

I get a stack overflow exception in the deserialization method:

Public static T DeserializeObject & lt; T & gt; (String xml) {t result; Var ser = new XmlSerializer (typef (t)); Var buffer = stringutuity 8 bitratere (XML); (Use the Var stream = new memorystream (buffer, 0, buffer, langhe)) {result = (t) sir. Direialize (stream); } Return results; }

Does anyone know what I am doing?

I'm not sure that this is related to the problem, but it is still stable as a deserillation method Do not call ...

  var msgColl = MessageObjectCollection.Deserialize (xml); Instead of  

...

  var msgColl = New MessageObjectCollection (). Deserialize (xml);  

??


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -