AppDomainSetup domainSetup = new AppDomainSetup();
// Assign a global path that includes "prinergyweb\bin"
domainSetup.ApplicationBase = @"E:\Projects\IPP\main\prinergyweb";
domainSetup.PrivateBinPath = @"bin";
AppDomain newDomain = AppDomain.CreateDomain("Test", null, domainSetup);
newDomain.Load("A");
我确保所有路径都是正确的,但它仍然会引发" FileNotFound" ......为什么? 你认为有多少原因会导致这个问题? (我已确定" A.dll"存在)。
其他信息:
PS1:我的光盘被压缩了
PS2:A.dll不是一个强名称的dll。
PS3:路径是我的PerForce的映射路径。
答案 0 :(得分:0)
问题在于AppDomain.Load
程序集被加载到两个域中。
如果当前AppDomain
对象表示应用程序域A,并且从应用程序域B调用Load方法,则程序集将加载到两个应用程序域中。
当前域需要了解这些程序集并加载它们。
如果您使用Assembly Binding Log Viewer,您会看到新创建的域从私有bin路径加载程序集,但当前的app域不会。
这就是为什么你得到"文件未找到"。
的例外此方法仅用于将装配加载到当前 应用领域。提供此方法是为了方便 无法调用静态Assembly.Load的互操作性调用者 方法。要将程序集加载到其他应用程序域,请使用a CreateInstanceAndUnwrap等方法。
如果你想从其他位置加载一些程序集,你应该像我在这个答案中说的那样:Assembly loaded from Resources raises Could not load file or assembly并处理AppDomain.AssemblyResolve Event