Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Normally, you should add an [XmlInclude] to the ResponseObject class. In this case, it doesn't work because of the SerializableDictionary that you're using. That class creates another XmlSerializer in its implementation, and therefore it doesn't care about your [XmlInclude]'s. Basically it just cannot handle your use case. You should switch from the XmlSerializer to the DataContractSerializer which handles the Dictionary class and supports the [KnownType] attribute to register additional types: <a href="http://pastebin.com/vGLSaxHF" rel="noreferrer">http://pastebin.com/vGLSaxHF</a> . Also note that it's pointless to add [DataContract] and [DataMember] attributes in your current case because the XmlSerializer ignores those attributes, they are used by the DataContractSerializer only. Or if you're not sure how to change your serializer (I know I'm not) then you should either not be using a Dictionary or change the SerializableDictionary implementation to handle the dynamic object types that you want to use (find every line where it creates a new XmlSerializer). Or, as an alternative, define a base class for all your objects that you will ever put into the dictionary and do it like this:</p> <pre><code>[XmlInclude(typeof(Class1), XmlInclude(typeof(Class2)), etc] public class AbstractBase { } public class Class1 : AbstractBase { ... } public class Class2 : AbstractBase { ... } public class BigClass { public SerializableDictionary&lt;string, AbstractBase&gt; Dictionary { get; set; } } </code></pre> <p>This way, when the SerializableDictionary creates its own XmlSerializer, it will recognize the AbstractBase and from there, all of its descendants.</p>
 

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