Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric List XML Serialization with different classes
    primarykey
    data
    text
    <p>I have got the following code:</p> <p><strong>BaseContent.cs</strong></p> <pre><code>public class BaseContent { // Some auto properties } </code></pre> <p><strong>News.cs</strong></p> <pre><code>public class News : BaseContent { // Some more auto properties } </code></pre> <p><strong>Events.cs</strong></p> <pre><code>public class Event : BaseContent { // Some more auto properites } </code></pre> <p><strong>GenericResponse.cs</strong></p> <pre><code>public class GenericResponse&lt;T&gt; { [XmlArray("Content")] [XmlArrayItem("NewsObject", typeof(News)] [XmlArrayItem("EventObject", typeof(Event)] public List&lt;T&gt; ContentItems { get; set; } } </code></pre> <p><strong>NewsResponse.cs</strong></p> <pre><code>public class NewsResponse : GenericResponse&lt;News&gt; {} </code></pre> <p><strong>EventResponse.cs</strong></p> <pre><code>public class EventResponse : GenericResponse&lt;Event&gt; {} </code></pre> <p>As you can see, I have a base class <strong>BaseContent</strong> and two classes deriving from it. Next I have a generic response class, since the structure of the xml-files is always the same, but they differ in some properties. </p> <p>I thought I can specify with the <code>[XmlArrayItem]</code> which name to use for a specific class. But now I get the error:</p> <blockquote> <p>System.InvalidOperationException: Unable to generate a temporary class (result=1). error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.</p> </blockquote> <p>I can not add this reference, because I'm working on a Windows 8 App.</p> <p>If I comment out one of the <code>[XmlArrayItem]</code> it is working well.</p> <p>Anyone got an idea to solve this problem?</p> <p><strong>Update</strong> I can <strong>not</strong> use DataContractSerializer, because I <strong>have to</strong> use XmlAttributes</p>
    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