-
Notifications
You must be signed in to change notification settings - Fork 934
Description
Currently in DefaultDynamicProxyMethodCheckerExtensions methods IsProxiable
and ShouldBeProxiable
are treating overridden Finalize
methods as proxiable:
...
&& (method.DeclaringType != typeof(object) || !"finalize".Equals(method.Name, StringComparison.OrdinalIgnoreCase))
...
Both of these methods are used for lazy loading.
If during finalization object is not yet loaded, lazy proxy attempts to pull it from DB.
Since Finalize is called by GC at random times and random threads, it is unlikely that session will still be open during Finalize.
In most cases Finalize for lazy not yet loaded proxies throws an exception "Could not initialize proxy - no Session".
This bug occurs only if proxyable class has a base class, that is overriding Finalize
, ie:
class Base { ~Base() { } }
class LazyChild : Base { } // this class will not be finalized
I've created a small demonstration project: https://github.com/ssharunas/nhibernate-finalization-bug-demonstration
IMHO Finalize should not be proxyable even in delivered classes.