If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: System.InvalidOperationException

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.

Re: System.InvalidOperationException

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");

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.