Note that there are some explanatory texts on larger screens.

plurals
  1. POXml String to object in c# using XDocument
    primarykey
    data
    text
    <p>I can't seem to parse my xml string to a custom object. Here is my code:</p> <pre><code> private Account parseXmlToAccount (String xml) { XDocument doc = XDocument.Parse(xml); Console.Out.WriteLine("a" + xml); List&lt;Account&gt; result = ( from x in doc.Root.Elements("user") select new Account() { Session = (string) x.Element("session").Value, User = (string) x.Element("user").Value }).ToList(); Console.Out.WriteLine("b"); return result.First(); </code></pre> <p>And Account.cs:</p> <pre><code>class Account { public string Session { get; set; } public string User { get; set; } public override string ToString() { return Session + " " + User; } } </code></pre> <p>and my xml string:</p> <pre><code>&lt;user&gt; &lt;session&gt;7981239761293767891&lt;/session&gt; &lt;user&gt;873948797862364&lt;/user&gt; &lt;/user&gt; </code></pre> <p>and my error message:</p> <pre><code>UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at testMonoAndroidApp.LoginManager.&lt;parseXmlToAccount&gt;m__4 (System.Xml.Linq.XElement) &lt;0x00044&gt; at System.Linq.Enumerable/&lt;CreateSelectIterator&gt;c__Iterator27`2&lt;System.Xml.Linq.XElement, testMonoAndroidApp.Account&gt;.MoveNext () &lt;0x0015b&gt; at System.Collections.Generic.List`1&lt;testMonoAndroidApp.Account&gt;.AddEnumerable (System.Collections.Generic.IEnumerable`1&lt;testMonoAndroidApp.Account&gt;) &lt;0x000ab&gt; at System.Collections.Generic.List`1&lt;testMonoAndroidApp.Account&gt;..ctor (System.Collections.Generic.IEnumerable`1&lt;testMonoAndroidApp.Account&gt;) &lt;0x00093&gt; at System.Linq.Enumerable.ToList&lt;testMonoAndroidApp.Account&gt; (System.Collections.Generic.IEnumerable`1&lt;testMonoAndroidApp.Account&gt;) &lt;0x0003b&gt; at testMonoAndroidApp.LoginManager.parseXmlToAccount (string) &lt;0x0012f&gt; ... </code></pre>
    singulars
    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.
 

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