Ошибка при десериализации объекта - C# (183995)
Формулировка задачи:
<?xml version="1.0"?> <Command xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <First>First</First> <Second>Second</Second> <Thrid>Thrid</Thrid> <Four>Four</Four> </Command>
public class Command
{
[XmlElement("First")]
public string FirstCommand;
[XmlElement("Second")]
public string SecondCommand;
[XmlElement("Thrid")]
public string ThridCommand;
[XmlElement("Four")]
public string FourCommand;
public Command(string a, string b, string c, string d)
{
FirstCommand = a;
SecondCommand = b;
ThridCommand = c;
Commandd = d;
}
public Command() { }
} using (var stream = new MemoryStream())
{
var command = new Command("First","Second","Thrid","Four");
var ser = new XmlSerializer(command.GetType());
ser.Serialize(stream, command);
ser.Deserialize(stream); // Здесь ошибка.
}Решение задачи: «Ошибка при десериализации объекта»
textual
Листинг программы
ser.Serialize(stream, command); stream.Position = 0; ser.Deserialize(stream);