Thursday, August 18, 2011

XSD 2d buug

If you get array related stuff like:

Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'Data[]' to 'Data'
error CS0029: Cannot implicitly convert type 'Data' to 'Data[]'


read on, otherwise you might be facing something different.

The problem is the xsd.exe tool has a bug when it comes to mapping to a multidimensional array. In most cases you can easily fix it by hand.

In my case, I ran a search on the Data type name in the generated file, and I found this:

[System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data), IsNullable=false)]
public Data[][] Row



As it can be seen, the type of the elements of a Data[][] array is not Data, but Data[]. The only change required was:

[System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data[]), IsNullable=false)]
public Data[][] Row



Happy coding, and hopefully we'll be spared of this kind of framework bugs in the future.