I am trying to load a domain class by deserializing an xml file. Therefore, I used System.Collections.Generic.List in the domain class. But when I try to save the object using the Session object, it 1[MyFirstMapTest.Class5]' to type 'System.Collections.Generic.List error "Cannot pass an object of type" NHibernate.Collection.Generic.PersistentGenericBag 1[MyFirstMapTest.Class5]' to type 'System.Collections.Generic.List 1 [MyFirstMapTest.Class5 ] ". This problem was published in a previous discussion, and the answer was to use IList instead of List ( Cannot use an object of type NHibernate.Collection.Generic.PersistentGenericBag to List )
But, if I use IList, then I cannot deserialize xml in the Domain class.
XmlTextReader xtr = new XmlTextReader(@"C:\Temp\SampleInput.xml"); XmlSerializer serializer = new XmlSerializer(objClass5.GetType()); objClass5 = (MyFirstMapTest.Class5)serializer.Deserialize(xtr); session.Save(objClass5);
Throws an error below "Cannot serialize an xxxxx element of type System.Collections.Generic.IList`1 [[xxxxxxxxxx, Examples, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null]] because it is an interface."
I tried using a PersistentGenericBag instead of a List, but the PersistentGenericBag is not serializable. Therefore, deserialization does not work.
How can I solve this problem? Thanks for looking at this issue.
Mohan source share