the faster solution is before you serialize this object call the method .ToList();
if your problem is deserialize, make a deserialize with the type list, and set to a IList, like this: XmlSerializer serializer = new XmlSerializer(typeof(new List<Class5>())); StreamReader reader = new StreamReader(caminho); IList<Class5> listClass = (List<Class5>)serializer.Deserialize(reader); On Mon, May 20, 2013 at 12:26 AM, Murali Mohan <mohan....@gmail.com> wrote: > I am trying to load the domain class by deserializing an xml file. So I > have used List in the domain class. But when I try to save the object using > Session object then it is failing with exception "Unable to cast object of > type > 'NHibernate.Collection.Generic.PersistentGenericBag`1[MyFirstMapTest.Class5]' > to type 'System.Collections.Generic.List`1[MyFirstMapTest.Class5]'." This > issue was posted in some of the previous discussion and the answer was to > use use IList<int> instead of List<int>( > http://stackoverflow.com/questions/1638593/unable-to-cast-object-of-type-nhibernate-collection-generic-persistentgenericbag > ) > > But, If I use IList then I am unable to Deserialize the xml in to Domain > class. It gives another error "Cannot serialize member xxxxx of type > System.Collections.Generic.IList`1[[xxxxxxxxxx, Examples, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null]] because it is an interface." > I have tried to use PersistentGenericBag instead of List but > PersistentGenericBag is not serializable. So Deserialization is not working. > > How can I resolve this issue? Thank you for looking at this issue. > > Regards, > Murali > > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to fluent-nhibernate+unsubscr...@googlegroups.com. > To post to this group, send email to fluent-nhibernate@googlegroups.com. > Visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en > . > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Rene Felix Correa Analista Desenvolvedor http://renefc3.wordpress.com -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To unsubscribe from this group and stop receiving emails from it, send an email to fluent-nhibernate+unsubscr...@googlegroups.com. To post to this group, send email to fluent-nhibernate@googlegroups.com. Visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en. For more options, visit https://groups.google.com/groups/opt_out.