【问题标题】:Current AppDomain loading assemblies outside of application base?当前 AppDomain 在应用程序库之外加载程序集?
【发布时间】:2011-09-27 10:24:01
【问题描述】:

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

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

为什么会这样?我怀疑它与执行 AppDomain 中需要可用的元数据有关,并且它是通过“跨界”从新域传回的,因此调用域也在加载程序集。但!我认为一个程序集不能在它的 ApplicationBase 之外加载,除非它在 ​​GAC 中,在这种情况下,它不是。

谁能帮我解惑?

【问题讨论】:

    标签: .net assemblies clr appdomain


    【解决方案1】:

    为了不将第二个appdomain的程序集加载到父域中,不能使用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();    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多