6

由于 AppDomain.AppendPrivatePath() 已过时,我试图弄清楚如何在我的项目中为当前 AppDomain 指定 PrivateBinPath,而无需启动一个全新的 AppDomain,并且以后能够访问它。

我知道我可以在 AppDomainSetup 对象上设置 PrivateBinPath(如果我想创建一个新的 AppDomain 就可以了),而且我也知道我可以将它添加到我的 app.config 中,如下所示:

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath=".\AlternateLookupPath" />
    </assemblyBinding>
  </runtime>

但是,将此条目添加到我的 app.config 时,AppDomain.CurrentDomain.SetupInformation.PrivateBinPath 属性为空。

4

2 回答 2

6

利用

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="AlternateLookupPath" />
    </assemblyBinding>
  </runtime>

根据http://msdn.microsoft.com/en-us/library/823z9h8w.aspx已经privatePath被解释为“应用程序基目录的子目录”......所以我怀疑使用.\会以某种方式搞砸......

于 2011-09-17T21:59:58.347 回答
4

从文档:

如果为 PrivateBinPath 指定的目录不在 ApplicationBase 下,它们将被忽略。

因此,您需要确保您添加的路径在 ApplicationBase 下。

然而,这只适用于 app.config。如果您需要在运行时执行此操作,请按照文档中的说明使用 AssemblyResolve 事件:

http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx

于 2009-08-28T16:55:17.763 回答