获取对象的应用程序域应用程序、对象

2023-09-04 23:47:49 作者:長得太帥忚四㈠種檌

有没有什么办法,以确定其中的AppDomain是创建一个对象或对象句柄实例?

Is there any way to determine in which AppDomain was an object or ObjectHandle instance created?

推荐答案

从另一个应用程序域中的对象是透明代理。有可能得到真正的代理服务器和访问私有字段包含域ID:

An object from another app domain is a transparent proxy. It is possible to get the real proxy and access the private field that contains the domain id:

public static int GetObjectAppDomain(object proxy)
{
    RealProxy rp = RemotingServices.GetRealProxy(proxy);
    int id = (int)rp.GetType().GetField("_domainID", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(rp);
    return id;
}

如果不知道可能的应用程序域的列表,这里 是一种方法,让所有应用程序域的列表中。

If the list of possible app domains isn't known, here is a way to get the list of all app domains.