I'm using Castle DynamicProxy to add an interceptor to my types. Now I need to get the underlying base type (NOT the proxy itself).
I found a few hints on SO that suggested to use the ProxyUtil class like this:
object realInstance = ProxyUtil.GetUnproxiedInstance(proxyInstance);
This does not seem to work as
bool isProxy = ProxyUtil.IsProxy(realInstance);
is always true.
I also tried using the following code snippet, which is essentially what ProxyUtil is doing:
var accessor = proxyInstance as IProxyTargetAccessor;
var realInstance = accessor.DynProxyGetTarget();
with the same results, realInstance is still a proxy.
What am I missing here?
See Question&Answers more detail:os