How to do xml serilization for derived entity

34 Views Asked by At
public abstract class Base
{
    //abstract methods
}

public class Derived1 : Base
{
    //method implementations
}

public class Derived2 : Derived1
{
    //method implementations
}

I am doing serilization with "Derived2"

        var serializer = new XmlSerializer(typeof(Derived2));
        serializer.Serialize(stringwriter, dataToSerialize);

It gives exception for Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. and unable to generate xmldocument

Now, problem is, I can't include xmlinclude attribute on parent entities as I do not have any control on parent entities. I have full control on most derived entity derived2.

Any solution to achieve serialization for this.

0

There are 0 best solutions below