当我启动只有一个AppDomain的应用程序时,AppDomain.CurrentDomain.SetupInformation.PrivateBinPath为null.即使我在MyApp.exe.config中设置了探测路径,如下所示.
我会想到AppDomain.CurrentDomain.SetupInformation.PrivateBinPath包含字符串"Dir1;Dir2;Dir3".
如何访问MyApp.exe.config中配置的探测路径?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Foo" value="Bar" />
</appSettings>
<startup>
<!-- supportedRuntime version="v1.1.4322" / -->
</startup>
<runtime>
<gcConcurrent enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<publisherPolicy apply="yes" />
<!-- Please add your subdirectories to the probing path! -->
<probing privatePath="Dir1;Dir2;Dir3" />
</assemblyBinding>
</runtime>
<system.windows.forms jitDebugging="true" />
</configuration>
Run Code Online (Sandbox Code Playgroud)
更新
正如Hans Passant指出下面的评论,SetupInformation.PrivateBinPath没有为主appdomain设置.所以上面的方法不起作用.您有什么建议来模拟融合在探测路径中搜索程序集的方式,或者至少考虑<probing privatePath="" />当前应用程序配置?我能想到的最好的事情是<probing privatePath="" />当前域是主appdomain(AppDomain.CurrentDomain.IsDefaultAppDomain()是true)时手动从App.config 读取.有没有更好的办法? …