I got an error trying to deserialize an xml to a class in .NET. I took an xml file and create an xsd from it using .net xsd tools, Then i created the class from the xsd i generated with the same tool.
I am getting this excpetion : 'Object cannot be stored in an array of this type' and 'There is an error in XML document (8, 144)'. In that line in the xml i got this :
<events>
<event assist="" assistid="" extra_min="" id="21775794" minute="87" player="O. Atia" playerid="" result="[0 - 1]" team="away" type="goal"/>
</events>
this is the generated c# property:
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("event", typeof(livescoreLeagueMatchEventsEvent), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public livescoreLeagueMatchEventsEvent[][] events {
get {
return this.eventsField;
}
set {
this.eventsField = value;
}
}
this is the parsing code:
XmlSerializer deserializer = new XmlSerializer(typeof(T));
using (XmlReader reader = XmlReader.Create(path))
{
return (T)deserializer.Deserialize(reader);
}
This is the generated xsd :
<xs:element name="events" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="event" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="assist" type="xs:string" />
<xs:attribute name="assistid" type="xs:string" />
<xs:attribute name="extra_min" type="xs:string" />
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="minute" type="xs:string" />
<xs:attribute name="player" type="xs:string" />
<xs:attribute name="playerid" type="xs:string" />
<xs:attribute name="result" type="xs:string" />
<xs:attribute name="team" type="xs:string" />
<xs:attribute name="type" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I thought the xsd tools are creating correct class structure, and thought it will work without any change in code at all. Tried to step into the serializer deserialize method without any success...
livescoreLeagueMatchEventsEvent[]