给出这个加载汇编代码:
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 应用程序域;手册(代理)没有我的程序集,在类的实例之外。