I’m using an XmlSerializer to deserialize some XML into an object. The problem i’m having is once i’ve deserialized successfully, one of my properties which is an array has the property isFixedSize set to true.
I need to add to this array manually at a later stage, but can’t.
Here’s my object (other properties omitted for brevity)
namespace Omeda.Customer
{
[Serializable()]
[XmlRoot("Customer")]
public class Customer : Error
{
[XmlArray("CustomerDemographics")]
[XmlArrayItem("CustomerDemographic", typeof(CustomerDemographic))]
public Omeda.Customer.CustomerDemographic[] CustomerDemographics { get; set; }
}
}
And here’s the method I’m using to deserialize (again, code ommitted for brevity)
private T request_Get<T>(string url) where T : new()
{
object returnObject = new T();
try
{
var request = WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/xml";
request.Headers.Add("x-omeda-appid", this.API_KEY);
request.Timeout = 50000;
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
returnObject = (T)serializer.Deserialize(responseStream);
}
}
}
catch (WebException ex)
{
...
}
return (T)returnObject;
}
Once this object is returned, customer.CustomerDemographics.IsFixedSize returns true.
Any help on how to get round this, and why this is happening would be great.
IsFixedSizeis always true for an array. If you “need to add to this array manually at a later stage”, you should not be using an array; you should probably be using aList<CustomerDemographic>, or another collection type that can be grown.