Hi I am getting this error, when serializing to XML
Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'XYZ.ProducerChannel[][]' to 'XYZ.ProducerChannel[]'
error CS0029: Cannot implicitly convert type 'XYZ.ProducerChannel[]' to 'XYZ.ProducerChannel[][]'
Can someone help me with whats going on?
Depending classes:
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("CarrierAppointment", typeof(ProducerChannel[]), IsNullable=false)]
[System.Xml.Serialization.XmlArrayItemAttribute("DistributionChannelInfo", typeof(ProducerChannel), IsNullable=false, NestingLevel=1)]
public ProducerChannel[][][] Producer
{
get
{
return this.producerField;
}
set
{
this.producerField = value;
}
}
Usage:
var producer = new InitialPurchaseOrder.ProducerChannel{DistributionChannelName = division};
bdParty.Producer = new InitialPurchaseOrder.ProducerChannel[][][]// {{},{},{producer}};
{new InitialPurchaseOrder.ProducerChannel[][]
{new InitialPurchaseOrder.ProducerChannel[]{producer}}};
Error Line:
var serializer = new System.Xml.Serialization.XmlSerializer(txLife.GetType());
Related XSD:
<xs:element name="Policy" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Annuity" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="QualPlanType" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="tc" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Please let me know how to fix this.
Thanks,
Sounds like a bug in
xsd.exeI have stumbled upon a few times now, it doesn’t handle arrays of arrays correctly.If that’s the case you have to modify the generated classes so that the
XmlSerializercan work with it.Either the attributes or the type of the
Producerproperty is not correct.If you had posted the relevant section of the XML schema I could say it for certain, but try to change the type of the
Producerproperty fromProducerChannel[][][]toProducerChannel[][].If you can modify the XML schema maybe this link can help without the need to modify the C# classes after generating them.