当前 AppDomain 正在加载应用程序库之外的程序集?

发布于 2024-11-17 23:52:48 字数 456 浏览 1 评论 0原文

我正在创建一个新的沙箱 AppDomain,其 ApplicationBase 和 PrivateBinPath(例如清酒)已设置为 C:\MyApp。我的执行应用程序从 C:\SomewhereElse 运行。

当我 otherDomain.Load(...) 程序集时,我执行的 AppDomain 也在加载该程序集。我通过在加载之前检查 GetAssemblies() 以及在加载之后检查 GetAssemblies() 来确定这一点。

为什么会发生这种情况?我怀疑它与执行 AppDomain 中需要可用的元数据有关,并且它通过“跨边界”从新域传回,因此调用域也在加载程序集。但!我认为程序集无法在其 ApplicationBase 之外加载,除非它位于 GAC 中,但在本例中并非如此。

谁能帮助我解决困惑吗?

I'm creating a new sandbox AppDomain whose ApplicationBase and PrivateBinPath (for example sake) has been set to C:\MyApp. My executing application is running from C:\SomewhereElse.

When I otherDomain.Load(...) an assembly, my executing AppDomain is also loading the assembly. I'm determining this by checking GetAssemblies() before the load, and then also the GetAssemblies() after the load.

Why is this happening? I suspect it has something to do with the meta-data needing to be available in the executing AppDomain and it's passed back over from the new domain via 'Cross Boundary', so the calling domain is loading the assembly too. But! I thought that an assembly couldn't be loaded outside of it's ApplicationBase, unless it was in the GAC, which in this case, it's not.

Can anyone help with my confusion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅人 2024-11-24 23:52:48

为了不将第二个应用程序域的程序集加载到父域中,您不能使用 otherdomain.Load(...)。您必须在子 appDomain 中创建 MarshalByRefObject,并让该代码调用 AppDomain.Load(...)。

示例:

public class AppDomainInitializer : MarshalByRefObject
{
  public void Initialize() { AppDomain.Load(...); }
}

父域:

{
AppDomain otherDomain = AppDomain.CreateDomain(...);

// Create the object in the other domain
ObjectHandle oh = Activator.CreateInstance(otherDomain, assemblyNme, "AppDomainInitializer", ...);

// Marshall it to this domain
var initializer = (AppDomainInitializer) oh.UnWrap();

// Proxy the call to load up the other domain dll's
intializer.Initialize();    
}

In order to not load the second appdomain's assemblies into the parent domain, you can't use otherdomain.Load(...). You have to create a MarshalByRefObject in the child appDomain, and have that code call AppDomain.Load(...).

Example:

public class AppDomainInitializer : MarshalByRefObject
{
  public void Initialize() { AppDomain.Load(...); }
}

Parent Domain:

{
AppDomain otherDomain = AppDomain.CreateDomain(...);

// Create the object in the other domain
ObjectHandle oh = Activator.CreateInstance(otherDomain, assemblyNme, "AppDomainInitializer", ...);

// Marshall it to this domain
var initializer = (AppDomainInitializer) oh.UnWrap();

// Proxy the call to load up the other domain dll's
intializer.Initialize();    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文