0
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.

user3711357
  • 1,425
  • 7
  • 32
  • 54
  • Given an instance of `Derived2`, the above code works just fine: ` ` so can you create an example that fails? – stuartd Nov 27 '17 at 18:39
  • above example is failing, have instance of `Derived2` and doing `var serializer = new XmlSerializer(typeof(Derived2)); serializer.Serialize(stringwriter, dataToSerialize); //this line is getting failed.` – user3711357 Nov 27 '17 at 18:45
  • even adding - xmlinclude too its not working. – user3711357 Nov 27 '17 at 18:48
  • Seems to be working in LinqPad - https://i.stack.imgur.com/7vHbd.png – stuartd Nov 27 '17 at 18:53
  • here problem is weird, when I post data and use object to seriliaze then it gives me this exception, but writing `new Derived2()` is working fine. I am posting data from PostMan (web api) and just doing serilization. and it fails due to above error. – user3711357 Nov 27 '17 at 20:31

0 Answers0