xhafan / coreddd

A set of open-source .NET libraries helping with DDD (domain-driven design) and CQRS (command query responsibility segregation).
MIT License
69 stars 6 forks source link

Hot Reload seems not to work properly for ASP.NET Core #26

Open xhafan opened 2 years ago

xhafan commented 2 years ago

Error:

2022-04-26 13:06:35.722 +02:00 [ERR] An unhandled exception has occurred while executing the request.
System.InvalidCastException: Unable to cast object of type '<some entity>' to type 'NHibernate.Proxy.INHibernateProxy'.
   at PointOfInterestProxy.NHibernate.Proxy.INHibernateProxy.get_HibernateLazyInitializer()
   at NHibernate.Engine.StatefulPersistenceContext.Clear()
   at NHibernate.Impl.SessionImpl.Close()
   at NHibernate.Impl.SessionImpl.Dispose(Boolean isDisposing)
   at NHibernate.Impl.SessionImpl.Dispose()
   at CoreDdd.Nhibernate.UnitOfWorks.NhibernateUnitOfWork.RollbackAsync()
   at CoreDdd.AspNetCore.Middlewares.BaseUnitOfWorkMiddleware.InvokeAsync(HttpContext context, RequestDelegate next, IUnitOfWork unitOfWork)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

How to replicate: Hot Reload a change, execute the change couple of times.

xhafan commented 1 year ago

todo: create a test case to verify the issue: https://github.com/nhibernate/nhibernate-core/blob/master/CONTRIBUTING.md#creating-a-test-case-to-verify-the-issue

shmatt commented 7 months ago

Came across this issue when searching for a solution to the same problem I am facing, but not using coreddd.

It seems that this is an issue with nhibernate itself, and not specifically with this library

xhafan commented 7 months ago

That's my feeling as well. Wanted to reproduce it purely using NHibernate and not CoreDdd, but have no time to do that. Hopefully I will do it at some point in the future 🙂