【问题标题】:Why can I not find that assembly?为什么我找不到那个程序集?
【发布时间】:2014-03-27 16:43:59
【问题描述】:
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 的映射路径。

【问题讨论】:

  • E 驱动器是本地磁盘吗?因为例如网络驱动器映射(大部分)是每个用户的概念,因此下一个问题是,此代码是在 您的 帐户下运行还是在另一个帐户下运行?
  • 你到底想做什么?实际上,您可能正在尝试另一种方法。
  • 您需要检查执行代码的机器上是否存在“E:\Projects\IPP\main\prinergyweb”。

标签: c#


【解决方案1】:

问题是AppDomain.Load 程序集被加载到两个域中。

如果当前 AppDomain 对象代表应用程序域 A,并且从应用程序域 B 调用 Load 方法,则程序集将加载到两个应用程序域中。

当前域需要知道这些程序集并加载它们。

如果您使用Assembly Binding Log Viewer,您将看到新创建的域从私有 bin 路径加载程序集,但当前应用程序域没有。

这就是为什么会出现“找不到文件”的异常。

来自MSDN AppDomain.Load Method

此方法仅用于将程序集加载到当前 应用领域。提供此方法是为了方便 无法调用静态 Assembly.Load 的互操作性调用者 方法。要将程序集加载到其他应用程序域,请使用 CreateInstanceAndUnwrap 等方法。

如果你想从不同的位置加载一些程序集,你应该像我在这个答案中所说的那样做:Assembly loaded from Resources raises Could not load file or assembly 并处理AppDomain.AssemblyResolve Event

【讨论】:

    猜你喜欢
    • 2014-04-27
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2013-05-13
    • 2014-06-26
    • 1970-01-01
    相关资源
    最近更新 更多