Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag to type 'System.Collections.Generic.List -


i trying load domain class deserializing xml file. have used system.collections.generic.list in domain class. when try save object using session object failing exception "unable cast object of type 'nhibernate.collection.generic.persistentgenericbag1[myfirstmaptest.class5]' type 'system.collections.generic.list1[myfirstmaptest.class5]'." issue posted in of previous discussion , answer use use ilist instead of list(unable cast object of type nhibernate.collection.generic.persistentgenericbag list)

but, if use ilist unable deserialize xml in 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); 

it throwing below error "cannot serialize member xxxxx of type system.collections.generic.ilist`1[[xxxxxxxxxx, examples, version=1.0.0.0, culture=neutral, publickeytoken=null]] because interface."

i have tried use persistentgenericbag instead of list persistentgenericbag not serializable. deserialization not working.

how can resolve issue? thank looking @ issue.

you can create 2 properties in class:

public class sample {     private ilist<sample> _list;      [xmlignoreattribute]     public virtual ilist<sample> list     {                 {             return _list;         }         set         {             _list = value;         }     }      public virtual list<sample> list     {                 {             return (list<sample>)_list;         }         set         {             _list = value;         }     } } 

and map ilist property.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -