I am trying to save an array of lists of an object in C# with in a xml file. I succeeded to save a array of an object and a list of objects but not an array of lists of an o
Try converting the list to an array, before attempting to serialize it:
List[] MainArr = new List[1];
MainArr[0] = new List();
Box Box1 = new Box(1);
MainArr[0].Add(Box1);
var arr = Array.ConvertAll(MainArr, x => x.ToArray());
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(arr.GetType());
System.IO.StreamWriter fileWrite = new System.IO.StreamWriter(@"C:\Users\Giorgos\Desktop\ConsoleApplication1\ArrListBox.xml");
writer.Serialize(fileWrite, arr);
fileWrite.Close();
The above piece of code produces the following xml on my machine:
1