Note that there are some explanatory texts on larger screens.

plurals
  1. POdeserialization of just serialized data fails, why?
    primarykey
    data
    text
    <p>I am trying to serialize and deserialize objects in silverlight, but cannot seem to get it to work. Serializing works just fine but it complains about my rootObject not being expected. I don't get it because it it is Silverlight who generated the XML. </p> <p>Btw; i'm still new to C#</p> <p>I have a class which looks like:</p> <pre><code>[XmlRoot("DataStorage")] // has no effect public class DataStorage { public string type { get; set; } public string imgUrl { get; set; } public List&lt;AbstractionObject&gt; children { get; set; } public DataStorage() { type = "default"; children = new List&lt;AbstractionObject&gt;(); } } </code></pre> <p>When serialized by Silverlight it produces:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;DataStorage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;type&gt;default&lt;/type&gt; &lt;children /&gt; &lt;/DataStorage&gt; </code></pre> <p>However, when I attempt to deserialize it produces:</p> <p>System.InvalidOperationException was unhandled by user code Message=There is an error in XML document (2, 2).</p> <p>InnerException: System.InvalidOperationException Message=<code>&lt;DataStorage xmlns=''</code>> was not expected.</p> <p>My deserialization code is as follows:</p> <pre><code>// create the xmlSerializer for DataObject XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataObject)); // Open the file again for reading. StreamReader fileStream = new StreamReader(isoStore.OpenFile("IsoStoreFile.xml", FileMode.Open)); XmlReader xmlReader = XmlReader.Create(fileStream); DataObject deserializedObject = (DataObject)xmlSerializer.Deserialize(xmlReader); fileStream.Close(); Debug.WriteLine(deserializedObject); </code></pre> <p>Any idea?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload