I keep getting error
The type Domains.Logic.Class1+ChildBody was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
The problem is i already use XmlInclude attribute
.
[XmlInclude(typeof(ChildBody))]
public abstract class BaseBody
{
}
public class ChildBody : BaseBody
{
public string Message {get;set;}
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[Serializable]
public class EnvelopeModel
{
[XmlElement(ElementName = "Body")]
public BaseBody Body { get; set; }
}
public void Serialize()
{
using (TextWriter writer = new StreamWriter(@"g:\test\xml.xml", false, System.Text.Encoding.UTF8))
{
XmlSerializer serializer = new XmlSerializer(typeof(EnvelopeModel));
serializer.Serialize(writer, new EnvelopeModel { Body = new ChildBody { Message = "example"} });
}
}