[System.Security.SecurityCritical] // auto-generated
private static IntPtr GetServerContextForProxy(
Object tp, out ObjRef objRef, out bool bSameDomain, out int domainId)
{
// Note: the contextId we return from here should be the address
// of the unmanaged (VM) context object or NULL.
IntPtr contextId = IntPtr.Zero;
objRef = null;
bSameDomain = false;
domainId = 0;
if (IsTransparentProxy(tp))
{
// This is a transparent proxy. Try to obtain the backing
// RealProxy from it.
RealProxy rp = GetRealProxy(tp);
// Get the identity from the realproxy
Identity id = rp.IdentityObject;
if(null != id)
{
ServerIdentity serverID = id as ServerIdentity;
if (null != serverID)
{
// We are in the app domain of the server
bSameDomain = true;
contextId = serverID.ServerContext.InternalContextID;
domainId = Thread.GetDomain().GetId();
}
else
{
// Server is from another app domain
// (possibly from another process)
objRef = id.ObjectRef;
if (objRef != null)
{
contextId = objRef.GetServerContext(out domainId);
}
else
{
// Proxy does not have an associated ObjRef
// <
//Contract.Assert(false, "Found proxy without an objref");
contextId = IntPtr.Zero;
}
}
}
else
{
// This was probably a custom proxy other than RemotingProxy
Contract.Assert(
!(rp is RemotingProxy),
"!(rp is RemotingProxy)");
contextId = Context.DefaultContext.InternalContextID;
}
}
return contextId;
}