2012-07-10 80 views
2

我的c#应用程序正在加载一个C#dll。这个c#dll通过DllImport加载一个c dll。我希望这两个DLL都存在于当前工作目录的其他文件夹中。但我不想修改它的环境变量。我试过SetDllDirectory但无法加载这些DLL。 你有什么想法我可以做到这一点。从其他文件夹加载dll

+0

你是通过反射来加载吗? – 2012-07-10 11:04:06

+1

尝试http://stackoverflow.com/questions/1087794/c-sharp-load-a-dll-file-and-access-methods-from-class-within – 2012-07-10 11:05:05

+0

你得到什么错误?你确定这是因为这些文件夹? – joocer 2012-07-10 12:58:34

回答

0

尝试增加这对您的配置文件:

<?xml version="1.0"?> 
    <configuration> 
     <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <probing privatePath="FolderName;OtherFolderName"/> 
     </assemblyBinding> 
     </runtime> 
    </configuration> 

这些文件夹必须是你的应用程序目录的子目录。

+0

我能够通过在LoadFrom中指定路径加载c#dll,但无法加载C DLL(由C#Dll加载)。如果我在应用程序中尝试LoadLibrary,我可以加载C#和C DLL,因此SetDll目录工作正常。如果我把所有的DLL放在当前文件夹中,那么应用程序运行良好。 探测标签只加载C#的DLL,但无法加载其他文件夹的依赖关系。在这种情况下,它是C DLL。 – 2012-07-11 04:32:15