I have following classes, note that B inherits A:
[XmlInclude(typeof(B))]
public class A
{...}
public class B : A
{...}
When an instance of B is serialized, then the xsi:type attribute is added:
<A xsi:type="B">
Why does this happen? The result should be just <B>.
This is the code for serialization:
var b = new B();
using (var writer = new XmlTextWriterFull(stream, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
var s = new XmlSerializer(typeof(B));
s.Serialize(writer, b);
}
This doesn’t happen with other classes that I serialize. Is it because the classes are in different namespaces?
How can I workaround this problem?
Try this approach:
Here is code for serialization
And serialized result is: