简体   繁体   English

是否可以避免将一些程序集加载到“AppDomain”中?

[英]Is it possible to avoid to load some assembly loading into the `AppDomain`?

I need to load SomeMixedAssembly.dll into the additional domain (ie it is not the main domain) and unload that domain after finishing the task. 我需要将SomeMixedAssembly.dll加载到其他域(即它不是主域)并在完成任务后卸载该域。 Also the SomeMixedAssembly.dll loads the SomeMixedAssembly_2.dll which is necessary for its work. 此外, SomeMixedAssembly.dll加载了其工作所必需的SomeMixedAssembly_2.dll Both assemblies are mixed and written not by me. 两个组件都是混合的,不是我写的。 It is not a problem, but the problem is the SomeMixedAssembly.dll loads the SomeMixedAssembly_2.dll into the main domain also. 这是没有问题的,但问题是SomeMixedAssembly.dll加载SomeMixedAssembly_2.dll主域也。

Is it possible to avoid to load some assembly loading into the main AppDomain ? 是否可以避免将一些程序集加载到主AppDomain

Yes, you can intervene in the process of assembly loading, using for instance, AppDomain.AssemblyResolve event handler. 是的,您可以使用例如AppDomain.AssemblyResolve事件处理程序干预程序集加载过程。 But assemblies usually load lazy on demand and you can not just not to load them and expect that your program will work. 但程序集通常会根据需要加载延迟,您不能只是不加载它们并期望您的程序能够正常工作。 Assembly loaded in another AppDomain cannot automatically work as the original one by definition. 根据定义,在另一个AppDomain中加载的程序集不能自动作为原始程序。

But such intervention can be useful if you want to load assembly from unusual place, check some prerequisites or for searching bugs. 但是,如果您想从不寻常的地方加载程序集,检查一些先决条件或搜索错误,这种干预可能很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM