The NHibernate LINQ provider has a weak reference on the session, allowing 
the session to get garbaged collected if nothing else than the query 
provider references it.

If a Linq query is used after having let the session it is bound to go 
un-referenced, then this message may occur. This is a change in NHibernate 
5.0: previously, the weak reference was "resurrecting" the session instead, 
but in an unpredictable state.

Le mercredi 14 mars 2018 16:20:35 UTC+1, David_L a écrit :
>
> I upgraded my Project to NH5 last week. Now I have a question about a 
> Message I have never seen before: "Session has already been garbage 
> collected"
>
> My code was Querying through lazy linked (many-to-one/one-to-many) 
> Entities via LINQ. Everything worked without Exception in the past (with 
> NH4). A customer reported me this message. I personally have never seen 
> it...
>
> StackTrace of my customer report:
>
> Message:An error has occurred.,ExceptionMessage:Session has already been 
> garbage 
> collected,ExceptionType:System.InvalidOperationException,StackTrace: 
>  bei NHibernate.Linq.DefaultQueryProvider.get_Session()
>  bei NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression 
> expression, IQuery query)
>  bei NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
>  bei NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression 
> expression)
>  bei Remotion.Linq.QueryableBase`1.GetEnumerator()
>  bei System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
>  bei System.Linq.Enumerable.<DistinctIterator>d__63`1.MoveNext()
>  bei System.Linq.Buffer`1..ctor(IEnumerable`1 source)
>  bei System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
>  bei 
> MediaServices.Services.Implementation.ServiceBaseWebApi.FillModelExtras(Asset[]
>  
> assets)
>  bei MediaServices.Services.Implementation.OfferService.OfferGalery(Int64 
> offerProgramId)
>
> My code in OfferGalery loads some entiteis from database with a 
> Session.Query<xxx>().Where... Statement. Then I Fill my Model 
> (FillModelExtras) navigating through the loaded entities and 
> lazy-sub-entities.
>
> Under which conditions does this Message come up? And what can I do to 
> avoid it?
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to