InvalidCastException Error during serialization EF entities

Nov 29, 2011 at 7:35 PM

Hi,

I was trying to serialize an an object from Entity Framework.  It's a top level object graph and I'm getting this error message:

"Unable to cast object of type 'System.Data.Objects.DataClasses.EntityCollection`1[CaseEntities.Case]' to type 'System.Collections.ICollection'".

Is there a work around for this? 

Cheers.

Coordinator
Mar 21, 2014 at 5:23 PM
Hi, it should work in v.2.20.0.0 and above.

System.Data.Objects.DataClasses.EntityCollection does not support ICollection and therefore could not be serialized. Since 2.20 it's ok if the serialized object supports IEnumerable.