Reputation: 153
I'm trying to deserialize an xml with XmlSerializer and I get InvalidOperationException: was not expected. Here's the xml file:
<?xml version="1.0" encoding="us-ascii"?>
<ArrayOfplatform xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<platform>
<positionX></positionX>
<positionY></positionY>
<moveSpeed>10</moveSpeed>
<ID>1</ID>
</platform>
</ArrayOfplatform>
And the classes
public class platform : gameElement
{
//[Serializable]
private float moveSpeed;
public int ID;
}
public class gameElement
{
//[Serializable]
public float positionX, positionY;
}
If it matters, I'm trying to read stuff for a platformer game made in Unity.
Upvotes: 2
Views: 166
Reputation: 3787
There're couple of problems with your XML:
XmlSerializer
- element name should be ArrayOfPlatform
instead of ArrayOfplatform
. (uppercase P)platform.moveSpeed
is private in your class and cannot be serialized or deserialized with XmlSerializer
.positionX, positionY
are of type float
(value-type) and cannot have empty values in the XML. Should be 0
.Fix that, everything else is fine.
Upvotes: 1