I\'m not an NHibernate user; I write a serialization utility library. A user has logged a feature-request that I should handle NHibernate proxy classes, treating them the sa
I'm guessing that you don't really want to access the actual Nhibernate session. This code might better fit your needs:
///
/// Returns the real type of the given proxy. If the object is not a proxy, it's normal type is returned.
///
internal static Type GetRealType(this object proxy)
{
if (proxy is INHibernateProxy)
{
var lazyInitialiser = ((INHibernateProxy)proxy).HibernateLazyInitializer;
return lazyInitialiser.PersistentClass;
}
else
{
return proxy.GetType();
}
}
Hope that helps.