I have an run time object of type {System.Runtime.Remoting.Proxies.__TransparentProxy} which is created from an instance of class which is inherited from ContextBoundObject. This class raise an event to some other object, I need to convert this proxy object to original object. All objects are in default AppDomain on single system.
public abstract class ObjectBase : ContextBoundObject, IObjectBase
{
}
public IMessageSink GetObjectSink(MarshalByRefObject o, IMessageSink next)
{
_context = (ObjectBase)o;// as ObjectBase; does not give any error but type remains
/// transparent proxy in VS watch window.
// no property to get the underlying type of the proxy
return _aspect;
}
How to convert them into original object? Why proxy is cretaed if running on same memory
You can get the
RealProxyinstance for the transarent proxy by callingMarshalServices.GetRealProxy(), but getting the server object reference is then harder because the defaultRealProxyonly has non-public members exposing this reference (a protected methodGetUnwrappedServer()and an internal propertyUnwrappedServerObject). You can either get to those if theRealProxyis implemented by yourself or via reflection (if you have enough trust to perform this).