I have the following class:
public partial class ct_ServiceProductInfoWireless {
private object[] itemsField;
private bool directFulfillmentField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("NewWirelessLines", typeof(ct_WirelessLines))]
[System.Xml.Serialization.XmlElementAttribute("WirelessLine", typeof(ct_ServiceProductInfoWirelessWirelessLine))]
public object[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
ct_WirelessLines Class
public partial class ct_WirelessLines {
private ct_NewWirelessLine[] wirelessLineField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("WirelessLine")]
public ct_NewWirelessLine[] WirelessLine {
get {
return this.wirelessLineField;
}
set {
this.wirelessLineField = value;
}
}
}
The problem is when I serialize my ct_ServiceProductInfoWireless Object I get following Exception:
The type ct_WirelessLines[] may not be used in this context.
This is the serialization code:
var stringWriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(objectToSerialize.GetType());
serializer.Serialize(stringWriter, objectToSerialize); //Getting exception here
return stringWriter.ToString();
What is wrong?
ct_NewWirelessLine class
public partial class ct_NewWirelessLine {
private ct_NewRatePlan ratePlanField;
private ct_DataPlan dataPlanField;
private ct_OrderDevice deviceField;
private ct_PhoneNumber telephoneNumberField;
private string lineNumberField;
private bool isPrimaryLineField;
}
ct_ServiceProductInfoWirelessWirelessLine class
public partial class ct_ServiceProductInfoWirelessWirelessLine {
private ct_Device deviceField;
private ct_RatePlan ratePlanField;
private ct_InstallmentPlan installmentPlanField;
private string paymentArrangementField;
private ct_OptionalFeature[] optionalPackagesField;
private ct_WirelessFeature[] optionalFeaturesField;
private string lineNumberField;
private string primarySQNumberField;
private string secondarySQNumberField;
private st_CustomerType customerTypeField;
private bool customerTypeFieldSpecified;
private string ppuZipField;
private string wtnField;
private bool directFulfillmentField;
private bool directFulfillmentFieldSpecified;
}
ct_ServiceProductInfoWirelessWirelessLineandct_NewWirelessLineclasses, because when i created those custom classes it worked well, thus the problem is probably in those classes definitions.System.InvalidOperationException: The type ct_WirelessLines[] may not be used in this context.by assigningct_ServiceProductInfoWireless.Itemsto be an array of array ofct_WirelessLinesinstead of a 1d array:Items = new [] { new [] { new ct_WirelessLines() } }. Demo fiddle: dotnetfiddle.net/PaXdUR. The code compiles becauseItemsis just an array of objects, but won't serialize becauseXmlSerializerexpects only the objects of the two declared types in the array, and not some nested array. Could you be doing that?