无法跨AppDomains访问加载的程序集

时间:2013-02-04 15:46:01

标签: c# appdomain

提供此装入程序集代码:

public class LoadAssembly : MarshalByRefObject, ILoadAssembly
{
    private readonly AppDomain currentDomain;
    public LoadAssembly()
    {
        currentDomain = AppDomain.CurrentDomain;
    }

    public void LoadFromFile(string filePath)
    {
        //currentDomain has no assemblies:
        Assembly.LoadFrom(filePath);
        //currentDomain has assemblies:

    }
}

鉴于以下测试:

var appDomain = AppDomain.CreateDomain("test", null,
new AppDomainSetup
{
    ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
    ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
    ShadowCopyFiles = "false"
});
var t = typeof(LoadAssembly);

//appDomain has no assemblies.
var loader = (ILoadAssembly)appDomain.CreateInstanceFromAndUnwrap(t.Assembly.Location, t.FullName);

loader.LoadFromFile("some path to a correct dll.");

//issue appDomain still has no assemblies.

我正在尝试将程序集加载到新的AppDomain中。

然后断言他们所有的程序集都已加载到新的AppDomain中。

我可以看到在LoadAssembly.LoadFromFile中,currentDomain有我加载的程序集;

但是,当我尝试在我的LoadAssembly类之外使用appDomain时,它没有我期望的加载程序集。有什么想法吗?


var appDomain;手册(代理)没有我的程序集,在类的实例之外。

0 个答案:

没有答案