Hi,
I have a problem when trying to serialize class with field whose type is not known staticaly.
When I try to do something like:
StatementResponseBody srb = new StatementResponseBody();
srb.Statement = new AccountBalanceType();
srb.Statement.ExtendedAccountInformation = new PaymentAccountExtendedInformation();
srb.Serialize();
exception is thrown with inner exception message:
The type Service3.PaymentAccountExtendedInformation was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
but srb.Statement.Serialize();
serializes srb.Statement as excpected. How can I serialize srb
Class definitions are below.
[ Serializable]
public class StatementResponseBody
{
[ XmlElement(Namespace = " http://www.hide-link.com/ ;)]
public AccountBalanceType Statement;
internal string Serialize()
{
XmlSerializer ser = new XmlSerializer(this.GetType());
TextWriter tw = new StringWriter();
ser.Serialize(tw, this);
return tw.ToString();
}
}
[ Serializable]
public class AccountBalanceType
{
[XmlElement(Namespace = " http://www.hide-link.com/ ;)]
private ExtendedAccountInformationType _extendedAccountInformation;
public ExtendedAccountInformationType ExtendedAccountInformation
{
get { return _extendedAccountInformation; }
set { _extendedAccountInformation = value; }
}
internal string Serialize()
{
XmlSerializer ser = new XmlSerializer(typeof(AccountBalanceType));
TextWriter tw = new StringWriter();
ser.Serialize(tw, this);
return tw.ToString();
}
}
[ XmlInclude(typeof(PaymentAccountExtendedInformation))]
[ Serializable]
public class ExtendedAccountInformationType
{... }
[ Serializable]
public class PaymentAccountExtendedInformation : ExtendedAccountInformationType
{... }
.NET Development15
|