c# - 在探测 privatePath 时使用绝对路径

标签 c#

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

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

这不起作用,因为 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>

但还是得到一个System.IO.FileNotFound异常。

谢谢!

最佳答案

根据 MSDN :

You can use the element only in machine configuration or publisher policy files that also redirect the assembly version. ... If you are supplying a code base hint for an assembly that is not strong-named, the hint must point to the application base or a subdirectory of the application base directory.

您可能尝试在 app.config 中应用?

The directories specified in privatePath must be subdirectories of the application base directory.

关于c# - 在探测 privatePath 时使用绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9536256/

相关文章:

c# - 为什么在使用异步方法时会捕获类作用域变量,而在使用 Action<T> 时却不会(内部代码示例)?

c# - 这样的集合是否存在(Dictionary 和 HashSet 的功能)?

c# - 如何在 ASP.NET MVC 中获取 View 路径

c# - PLINQ (C#/.Net 4.5.1) 与 Stream (JDK/Java 8) 性能对比

c# - RSA_sign 和 RSACryptoProvider.VerifySignature

c# - 自动将 System.diagnostics.trace 消息记录到 Nlog 目标

c# - Entity Framework 核心——脚手架枚举

c# - CQRS 模式上的服务层

c# - 取 LINQ 中每个分组项目的 Top(X)

c# - 访问 TreeView 中的父节点?