当前 AppDomain 正在加载应用程序库之外的程序集?
我正在创建一个新的沙箱 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了不将第二个应用程序域的程序集加载到父域中,您不能使用 otherdomain.Load(...)。您必须在子 appDomain 中创建 MarshalByRefObject,并让该代码调用 AppDomain.Load(...)。
示例:
父域:
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:
Parent Domain: