I am using XmlSerializer against an XSD.EXE generated class.
XmlSerializer serializer = new XmlSerializer(obj.GetType());
Throws up
InvalidOperationException Unable to
generate a temporary class (result=1).
error CS0030: Cannot convert type
‘itemOrderItemsItem[]’ to
‘itemOrderItemsItem’ error CS0029:
Cannot implicitly convert type
‘itemOrderItemsItem’ to
‘itemOrderItemsItem[]’
The fix (labeled <!--fix...--> below) says to add some silly element to my schema, but this isn’t working. This fix is five years old. Is there a solution yet?
<xs:sequence>
<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="model" type="xs:string" minOccurs="0" />
<xs:element name="description" type="xs:string" minOccurs="0" />
<xs:element name="material" type="xs:string" minOccurs="0" />
<xs:element name="lot" type="xs:string" minOccurs="0" />
<xs:element name="serial" type="xs:string" minOccurs="0" />
<xs:element name="transferQty" type="xs:string" minOccurs="0" />
<xs:element name="shipQty" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="tmp" type="xs:string" /><!--fix...-->
If you have XML of the form
Xsd.exe will generate a xsd:
Then
Generates a class with two dimensional arrays (items[][]). I only wanted a one dimensional array. I changed the first line:
Now it works. Guess the serializer just barfs on two dimensional arrays. Luckily I dont need them.