If NHibernateUtil.Initialize() is performed on an uninitialized proxy, then IInterceptor.Instantiate gets called properly. However, the proxy calls the constructor directly if the result set of a query is iterated, and lazy-loading occurs.
Here is the stack trace:
Code:
MyCompany.Framework.Entities.dll!MyCompany.Framework.Entities.PluginLayer.PluginLayer() Line 30 C#
DynamicAssemblyProxyGen!CProxyTypeMyCompany_Framework_EntitiesPluginLayerEntities_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2.CProxyTypeMyCompany_Framework_EntitiesPluginLayerEntities_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2() + 0x2b1 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder = {System.DefaultBinder}, object[] args = {Dimensions:[1]}, System.Globalization.CultureInfo culture, object[] activationAttributes = null) + 0x24d bytes
mscorlib.dll!System.Activator.CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes) + 0x73 bytes
mscorlib.dll!System.Activator.CreateInstance(System.Type type, object[] args) + 0x11 bytes
Castle.DynamicProxy.dll!Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(System.Type type = {Name = "CProxyTypeMyCompany_Framework_EntitiesPluginLayerEntities_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2" FullName = "CProxyTypeMyCompany_Framework_EntitiesPluginLayerEntities_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2"}, Castle.DynamicProxy.IInterceptor interceptor = {NHibernate.Proxy.CastleLazyInitializer}, object[] argumentsForConstructor = {Dimensions:[0]}) + 0x71 bytes
Castle.DynamicProxy.dll!Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(System.Type baseClass = {Name = "PluginLayer" FullName = "MyCompany.Framework.Entities.PluginLayer"}, System.Type[] interfaces = {Dimensions:[1]}, Castle.DynamicProxy.IInterceptor interceptor = {NHibernate.Proxy.CastleLazyInitializer}, bool checkAbstract = false, object[] argumentsForConstructor = {Dimensions:[0]}) + 0x8c bytes
NHibernate.dll!NHibernate.Proxy.CastleProxyFactory.GetProxy(object id = "BaseApp ", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0xc2 bytes
NHibernate.dll!NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(object id = "BaseApp ", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0x3b bytes
NHibernate.dll!NHibernate.Impl.SessionImpl.DoLoadByClass(System.Type clazz = {Name = "PluginLayer" FullName = "MyCompany.Framework.Entities.PluginLayer"}, object id = "BaseApp ", bool checkDeleted = false, bool allowProxyCreation = true) + 0x264 bytes
NHibernate.dll!NHibernate.Impl.SessionImpl.InternalLoad(System.Type clazz = {Name = "PluginLayer" FullName = "MyCompany.Framework.Entities.PluginLayer"}, object id = "BaseApp ", bool eager = false, bool isNullable = false) + 0x6d bytes
NHibernate.dll!NHibernate.Type.EntityType.ResolveIdentifier(object id = "BaseApp ", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0x64 bytes
NHibernate.dll!NHibernate.Type.EntityType.ResolveIdentifier(object id = "BaseApp ", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object owner = {MyCompany.Framework.Entities.PluginRegistryEntryLayer}) + 0x71 bytes
NHibernate.dll!NHibernate.Impl.SessionImpl.InitializeEntity(object obj = {MyCompany.Framework.Entities.PluginRegistryEntryLayer}) + 0x19b bytes
NHibernate.dll!NHibernate.Loader.Loader.InitializeEntitiesAndCollections(System.Collections.IList hydratedObjects = Count = 2, object resultSetId = {NHibernate.Driver.NHybridDataReader}, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0x164 bytes
NHibernate.dll!NHibernate.Loader.Loader.DoQuery(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, NHibernate.Engine.QueryParameters queryParameters = {NHibernate.Engine.QueryParameters}, bool returnProxies = true) + 0x38a bytes
NHibernate.dll!NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, NHibernate.Engine.QueryParameters queryParameters = {NHibernate.Engine.QueryParameters}, bool returnProxies = true) + 0x56 bytes
NHibernate.dll!NHibernate.Loader.Loader.LoadCollection(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object id = "Y8BVX9QYXF", NHibernate.Type.IType type = {NHibernate.Type.StringType}) + 0x117 bytes
NHibernate.dll!NHibernate.Loader.Collection.CollectionLoader.Initialize(object id = "Y8BVX9QYXF", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0x4a bytes
NHibernate.dll!NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize(object key = "Y8BVX9QYXF", NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}) + 0x4c bytes
NHibernate.dll!NHibernate.Impl.SessionImpl.InitializeCollection(NHibernate.Collection.IPersistentCollection collection = {NHibernate.Collection.PersistentBag}, bool writing = false) + 0x1e4 bytes
NHibernate.dll!NHibernate.Collection.AbstractPersistentCollection.Initialize(bool writing = false) + 0xe5 bytes
NHibernate.dll!NHibernate.Collection.AbstractPersistentCollection.Read() + 0x2d bytes
NHibernate.dll!NHibernate.Collection.PersistentBag.GetEnumerator() + 0x2d bytes