Stop WCF Deserializing Empty ICollection into Zero Capacity Array

entity-framework-4.1, serialization, wcf

Solution

I'm surprised that more folks haven't run into this issue, as it hits you smack in the face when you try to use the EF T4-generated POCO objects over WCF. Specifically, the error I was getting said something like:

Exception: "Unable to set field/property Orders on entity type Datalayer.Customers. See InnerException for details."

InnerException: "An item cannot be added to a fixed size Array of type 'Datalayer.Order[]'."

At any rate, the only solution I've been able to come up with is the one that you mention, namely, modifying the T4 templates to use HashSet instead of ICollection. Doesn't strike me as the cleanest, but it seems to work.

Problem

I'm having a problem using WCF and Entity Framework 4.1 POCO objects (generated using T4 templates). My basic problem is that when sending a POCO object from my client to the service, WCF is deserializing a member variable of type ICollection as a fixed size array. On the client side I can tell visual studio to use IList instead of T[] - but I cant see any option like this on the server end. This causes no end of problems with several things, such as persisting these objects back to the database. Is there any way to tell WCF what object type to deserialize ICollection (or any array) as?

Original source