Hello,
I need to save my DetachedCriteria and load it later (I'm developing a query builder application). For this, I am using serialization/deserialization through the NHibernate.Util.SerializationHelper utility class.
More precisely, when I save the criteria I'm using
"bytes = SerializationHelper.Serialize(this);" and then save these bytes into a file. When deserializing it, I'm using "SerializationHelper.Deserialize(bytes)". All that is working fine if the DetachedQuery is not run before serializing it. I mean, if before serialization happens, the following lines are executed:
NHibernate.ISession s = QueryBuilder.SessionFactory.OpenSession();
ICriteria crit = criteria.GetExecutableCriteria(s);
IList results = crit.List();
('criteria' is my DetachedCriteria to be saved))
...in this case, I believe some of the session data (or session factory) are serialized too. And when trying to Deserialize the DetachedCriteria, it throws an exception.
Please help me finding a way to proper serialize this DetachedCriteria.It may be possible that the criteria be run before it is saved, so I have to know how to workaround this issue.
Below is the exception thrown when the criteria is deserialized using "SerializationHelper.Deserialize(bytes)".
Thanks in advance!
Message: "Key cannot be null.\r\nParameter name: key"
StackTrace:
" at System.Collections.Hashtable.get_Item(Object key)\r\n at NHibernate.Impl.SessionFactoryObjectFactory.GetNamedInstance(String name)\r\n at NHibernate.Impl.SessionFactoryImpl.GetRealObject(StreamingContext context)\r\n at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)\r\n at System.Runtime.Serialization.ObjectManager.DoFixups()\r\n at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)\r\n at NHibernate.Util.SerializationHelper.Deserialize(Byte[] data)\r\n
|