如何正确访问当前AppDomain的PrivateBinPath属性?

sco*_*ttm 6 c# appdomain

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

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

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath=".\AlternateLookupPath" />
    </assemblyBinding>
  </runtime>
Run Code Online (Sandbox Code Playgroud)

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

Yah*_*hia 6

使用

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="AlternateLookupPath" />
    </assemblyBinding>
  </runtime>
Run Code Online (Sandbox Code Playgroud)

根据http://msdn.microsoft.com/en-us/library/823z9h8w.aspx,privatePath它已被解释为"应用程序基本目录的子目录"...所以我怀疑使用.\是以某种方式弄乱了...

  • 我试过用这个,但不适合我.AppDomain.CurrentDomain.SetupInformation.PrivateBinPath属性仍为null. (2认同)