I am having this very strange problem trying to serialize a logging class using XmlSerializer. The code was generated using the wsdl.exe tool. A class that is serialized is declared as follows:
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "xxxxx")]
public partial class InheritedRequestA : BaseRequest
{
}
Serialization of other classes that also inherit from BaseRequest includes all non-inherited members, but not one of the public members from BaseRequest. BaseRequest is declared as follows.
[System.Xml.Serialization.XmlIncludeAttribute(typeof(InheritedRequestA))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(InheritedRequestB))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "xxxxx")]
public partial class BaseRequest
{
}
To serialize requests and responses together, I wrote a very simple Wrapper class that simply contains a request object and a response object. Code for serialization:
XmlSerializer serializer = new XmlSerializer(typeof(Wrapper));
string serializedObject = string.Empty;
using (MemoryStream stream = new MemoryStream())
{
serializer.Serialize(stream, wrapper);
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream))
{
serializedObject = reader.ReadToEnd();
}
}
Any thoughts on why public properties inherited from the base class do not receive serialization would be greatly appreciated.
EDIT: . ActivatorWrapper VersionRetrieverWrapper.
[Serializable]
[XmlInclude(typeof(Wrapper))]
[XmlInclude(typeof(ActivatorWrapper))]
[XmlInclude(typeof(VersionRetrieverWrapper))]
public class Wrapper
{
}
[Serializable]
public class VersionRetrieverWrapper : Wrapper
{
public InheritedRequestA Request { get; set; }
public InheritedResponseA Response { get; set; }
}