以下是我的目录结构
e:\测试\探测
目录探测包含一个可执行文件[Probing.exe],它加载dll文件(Probe.dll)。
代码是:
namespace Probing
{
class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.Load("Probe.dll");
if (asm != null)
{
Console.WriteLine("Assembly Probe is loaded");
}
else
{
Console.WriteLine("Assembly Probe is not loaded");
}
}
}
}
dll 文件 (Probe.dl) 位于子目录 ( e:\test\probing\CustomLibraries\Probe.dll ) 中。
我提供了 Probing.exe.config 文件,甚至 App.config 来定位程序集。
配置文件包含以下代码:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="CustomLibraries"/>
</assemblyBinding>
</runtime>
</configuration>
我收到 FileNotFound 异常,直到我将 dll 保留在 Bin 目录中。
我需要你的帮助。(我正在使用 Visual studio 2008 )
最佳答案
尝试调试此问题要做的第一件事是 setup Fusion logging - 这样你就会看到目录被选中。
探测仅适用于应用程序目录下的子目录,因此,正如您所说,如果您的应用程序位于 ...\bin 中,而您的库位于 ...\lib 中,则它将不起作用 - 它们需要位于...\bin\lib。
您需要使用codebase相反
关于ASP.NET 程序集探测问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1448020/