xmlns='' was not expected when deserializing nested classes
- by Mavrik
I have a problem when attempting to serialize class on a server, send it to the client and deserialize is on the destination.
On the server I have the following two classes:
[XmlRoot("StatusUpdate")]
public class GameStatusUpdate
{
public GameStatusUpdate()
{}
public GameStatusUpdate(Player[] players, Command command)
{
this.Players = players;
this.Update = command;
}
[XmlArray("Players")]
public Player[] Players { get; set; }
[XmlElement("Command")]
public Command Update { get; set; }
}
and
[XmlRoot("Player")]
public class Player
{
public Player()
{}
public Player(PlayerColors color)
{
Color = color;
...
}
[XmlAttribute("Color")]
public PlayerColors Color { get; set; }
[XmlAttribute("X")]
public int X { get; set; }
[XmlAttribute("Y")]
public int Y { get; set; }
}
(The missing types are all enums).
This generates the following XML on serialization:
<?xml version="1.0" encoding="utf-16"?>
<StatusUpdate>
<Players>
<Player Color="Cyan" X="67" Y="32" />
</Players>
<Command>StartGame</Command>
</StatusUpdate>
On the client side, I'm attempting to deserialize that into following classes:
[XmlRoot("StatusUpdate")]
public class StatusUpdate
{
public StatusUpdate()
{
}
[XmlArray("Players")]
[XmlArrayItem("Player")]
public PlayerInfo[] Players { get; set; }
[XmlElement("Command")]
public Command Update { get; set; }
}
and
[XmlRoot("Player")]
public class PlayerInfo
{
public PlayerInfo()
{
}
[XmlAttribute("X")]
public int X { get; set; }
[XmlAttribute("Y")]
public int Y { get; set; }
[XmlAttribute("Color")]
public PlayerColor Color { get; set; }
}
However, the deserializer throws an exception:
There is an error in XML document (2, 2).
<StatusUpdate xmlns=''> was not expected.
What am I missing or doing wrong?