1. Don't use ArrayList. That class has been obsolete since generics debuted in .NET 2.0
2. You cannot serialize an ArrayList, hence the InvalidOperation exception. ArrayList is not a typed collection and thus cannot be serialized directly. You can use a generic collection List<T> or convert the ArrayList to an array.
You're welcome. I would suggest a couple more changes though...
Code:
// I would make GetTicketsForOffline a static method instead of an instance method
ArrayList arrList = new TicketBL().GetTicketsForOffline();
// there are fancier ways to do this with LINQ, but this is fine
List<TicketVO> listResult = new List<TicketVO>();
foreach (TicketVO ticket in arrList)
{
listResult.Add(ticket);
}
// using this pattern ensures that the stream is disposed.
// if an error had occurred before you called Close previously
// you would have left the file with an open handle and perhaps
// not flushed the contents to disk.
using (FileStream fs = new FileStream(FILE_PATH, FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<TicketVO>));
serializer.Serialize(fs, listResult);
}
MessageBox.Show("List Pull complete");
Bookmarks