在探测privatePath时使用绝对路径

Pau*_*aul 12 c#

在C#控制台应用程序中,我试图<probing privatePath=""/>用来指向不在我的应用程序子目录中的dll.我正在使用:

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

这不起作用,因为privatePath正在我的应用程序中查找子目录.有没有办法以这种方式使用绝对路径?如果没有,指向位于我的应用程序之外的dll的最佳方法是什么?我也尝试使用<codebase>file:///道路,但仍然有System.IO.FileNotFound例外.

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity 
        name="MyLibrary" publicKeyToken="29989D7A39ACF230" />
      <codeBase
        version="2.0.0.0"
        href="http://file:///D:/Library/References/NLog.dll"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)

但仍有System.IO.FileNotFound例外.

谢谢!

the*_*ric 16

根据MSDN:

您只能在机器配置中使用该元素,或者 也可以使用也重定向程序集版本的发布者策略文件....如果要为没有强名称的程序集提供代码基础提示,则提示必须指向应用程序库或应用程序基目录的子目录.

你可能试过申请app.config

privatePath中指定的目录必须是应用程序基目录的子目录.