Подскажите пожалуйста почему в этом примере не проходит Xml сериализация объекта типа TestClass?
я уже незнаю что с ним делать что-бы это заработало. Помогите пожалуйста!!!
[Serializable]
public class TestClass
{
private string _name = string.Empty;
private int _intValue = int.MinValue;
private object _element = null;
public TestClass()
{
}
public TestClass(string name, int intValue)
{
_name = name;
_intValue = intValue;
int[] list = new int[3];
list[0] = 1;
list[1] = 2;
list[2] = 4;
_element = list;
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public int IntValue
{
get
{
return _intValue;
}
set
{
_intValue = value;
}
}
public object Element
{
get
{
return _element;
}
set
{
_element = value;
}
}
}
public class Program
{
static void Main(string[] args)
{
OurContainerSerializing();
}
private static void OurContainerSerializing()
{
try
{
TestClass obj = new TestClass("test1",1);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(TestClass));
StringWriter sw = new StringWriter();
xmlSerializer.Serialize(sw, obj);
string xml = sw.ToString();
StringReader sr = new StringReader(xml);
TestClass obj1 = (TestClass)xmlSerializer.Deserialize(sr);
int a = 1;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + (null!=ex.InnerException?ex.InnerException.Message:""));
}
}
}