Dear Members,
I am encountering a problem with the below class file. When I attept to serialize the class Money I get the exception
Message "There was an error reflecting type Test.Money'." string
The inner most exception is
_message "Cannot serialize object of type Test.Money'. Consider changing type of XmlText member 'Test.Money.Value' from System.Decimal to string or string array." string
When I removed the inheritance to ServicedComponent it works. Any insight into this problem?
Class Code
********
using System;
using System.EnterpriseServices;
namespace Test
{
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://abc.com")]
public class Money : ServicedComponent
{
private string mcurrency;
private decimal mValue;
private bool mcurrencySpecified;
[System.Xml.Serialization.XmlAttributeAttribute(DataType="token")]
public string currency
{
get
{
if ((this.mcurrency == null))
{
return "";
}
else
{
return this.mcurrency;
}
}
set
{
this.mcurrency = value;
this.mcurrencySpecified = true;
}
}
[System.Xml.Serialization.XmlTextAttribute()]
public decimal Value
{
get
{
return this.mValue;
}
set
{
this.mValue = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool currencySpecified
{
get
{
return this.mcurrencySpecified;
}
set
{
this.mcurrencySpecified = value;
}
}
}
}
Client Code to Serialize
*********
Test.Money mny = new Test.Money();
mny.currency = "USD";
mny.Value = 232.22m;
System.IO.StringWriter sw = new System.IO.StringWriter(new System.Text.StringBuilder());
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(mny.GetType());
serializer.Serialize(sw, mny);