开发者

Error on serializing XML

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" /&开发者_如何学Cgt;
                                </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.exe I 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 XmlSerializer can work with it. Either the attributes or the type of the Producer property 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 Producer property from ProducerChannel[][][] to ProducerChannel[][].

If you can modify the XML schema maybe this link can help without the need to modify the C# classes after generating them.


I think the error message is pretty clear. You have the property as ProducerChannel[][] (or ProducerChannel[][][]), but your XmlArrayItem attribute is trying to serialize it as ProducerChannel[].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜