nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

Error while deserializing entity with lazy="false"

Open heikar opened this issue 7 years ago • 5 comments

Hi,

i get an strange behavior when i try to deserialize an entity wich is not lazy.

public class Entity
{
    public System.Collections.Generic.ISet<EntityDetail> DetailList { get; set; }
}

using (var session = ...)
{
    var obj = session.Get<Entity>(id);
    using (var stream = ...)
    {
        var serializer = new Hyperion.Serializer();
        serializer.Serialize(obj, stream);
        stream.seek(0, System.IO.SeekOrigin.Begin);
        var objNew = serializer.Deserialize<Entity>(stream);
    }
}

When i invoke the deserializing then the following message occurs:

"Initializing[Unavailable#]-failed to lazily initialize a collection, no session or session was closed"

If i use the BinaryFormatter then the deserialization works.

I dont understand it because the lazy-loading ist disabled for the two entities and the mapped collection.

heikar avatar Oct 30 '18 12:10 heikar

Maybe Hyperion is plagued by the Shrike, wrecking havoc on deserialization.

More seriously, what is this Hyperion serializer? Without complete details (including used mappings), we will likely not reproduce it. So it will be unlikely to be diagnosed.

If possible, consider submitting a test case in a PR, see contributing.

fredericDelaporte avatar Oct 30 '18 13:10 fredericDelaporte

Hi Frédéric,

tanks for your answer.

Hyperion is a high performance serializer.

I will submit the test case and entity/mapping files.

heikar avatar Oct 30 '18 13:10 heikar

@heikar what is the full stack trace?

hazzik avatar Dec 05 '18 23:12 hazzik

Hi @hazzik,

sorry for the long duration for the answer.

The error occurs e.g. by the deserialization of nested ISet:

Initializing[Unavailable#]-failed to lazily initialize a collection, no session or session was closed

   bei NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationException(String message)
   bei NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationExceptionIfNotConnected()
   bei NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writing)
   bei NHibernate.Collection.Generic.PersistentGenericSet`1.Add(T o)
   bei lambda_method(Closure , Object , Object )
   bei Hyperion.SerializerFactories.EnumerableSerializerFactory.<>c__DisplayClass10_1.<BuildSerializer>b__1(Stream stream, DeserializerSession session)
   bei Hyperion.ValueSerializers.ObjectSerializer.ReadValue(Stream stream, DeserializerSession session)
   bei lambda_method(Closure , Stream , DeserializerSession )
   bei Hyperion.ValueSerializers.ObjectSerializer.ReadValue(Stream stream, DeserializerSession session)
   bei Hyperion.Serializer.Deserialize(Stream stream)
   bei NHibernateCollectionTest.Program.Main(String[] args) in

Thank you :)

Regards heikar

heikar avatar Feb 18 '19 15:02 heikar

Hi, Were you able to solve the above issue?

ic185054 avatar Jun 28 '24 06:06 ic185054