Front Range Code Camp v2 this Saturday!#
Front Range Code Camp is this Saturday.  The schedule is posted so please come and check out some of the sessions.
Friday, May 18, 2007 2:42:18 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

Serializing IList#

I have been working on a WCF implementation lately and instead of exposing List<T> I wanted to expose IList<T> but found this is not as easy as it may first seem.  Say you create a new IList<T> (i.e. IList<Foo> foos = new List<Foo>()) then you serialize it.  What comes out on the other end is really a read only array which is what IList<T> works with under the covers.  If you just return IList<T> that is a new’d up List<T> that has not been serialized yet you do not see any real problems but it is when you take a request with an IList<T> and you want to include that same list that was sent in in the response.  At compile time there is not problem but at runtime this blows up and crashes the application in IIS because it is a readonly array.

In the end I decided to expose List<T> instead of IList<T> considering this is a private interface that is talking .NET to .NET.

Friday, May 18, 2007 2:41:55 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

All content © 2008, John Luif