从另一个dll引用一个DLL [英] Reference a DLL from another DLL
问题描述
我有一个C#应用程序,让我们称之为APP.EXE。它引用了一个名为DLL A.DLL这反过来又引用了另一个DLL,即B.DLL。然而,在它们被引用的方式是有点不同。在A.DLL的代码,它直接引用B.DLL(通过Project>参考>添加B.DLL)。但是我有APP.EXE代码中使用的Assembly.Load()等在运行时加载A.DLL。
因此,要回顾一下,APP.EXE ----(运行时加载)---> ---- A.DLL(直接引用)---> B.DLL
所有的三件事(APP.EXE,A.DLL和B.DLL)驻留在同一目录中,让我们说ExeDir。现在,我想要做的是,把A.DLL和B.DLL在ExeDir的子目录。我可以通过使用A.DLL指定的路径中的App.config文件,并要求APP.EXE从该路径加载A.DLL做到这一点。到目前为止好。
但问题是,当我这样做,.NET给我的错误,指出它无法找到B.DLL这是在同一个目录作为A.DLL。如果我将其移回原来的目录(相同的目录APP.EXE),那么它工作正常。这意味着,我可以把A.DLL在子目录,但B.DLL需要在原来的目录。
有没有什么办法中,我可以保持两个DLL文件中的子目录?
添加<探测>
在你的app.config元素:
的 http://msdn.microsoft.com/en-us/library/823z9h8w.aspx
<预类=郎咸平的XML prettyprint-覆盖>
<结构>
<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
<探测privatePath =斌; bin2\subbin; BIN3/>
< / assemblyBinding>
< /运行>
< /结构>
I have a C# application program, let's call it App.exe. It references a DLL named A.dll which in turn references another DLL, namely, B.dll. However the way in which they are referenced is a bit different. In the code of A.dll, it has directly referenced B.dll (by going to Project > References > Add B.dll). However my App.exe has code to load A.dll at runtime using Assembly.Load() etc.
So to recap, App.exe ---- (runtime loading) ---> A.dll ---- (direct reference) ---> B.dll
All three things (App.exe, A.dll and B.dll) reside in the same directory, let's say ExeDir. Now what I want to do is, put A.dll and B.dll in a sub directory of ExeDir. I can do this by using an App.config file that specify the path of A.dll and asking the App.exe to load A.dll from that path. So far so good.
However the problem is that when I do this, .NET gives me an error saying that it cannot find B.dll which is in the same directory as A.dll. If I move it back to the original directory (the same directory as App.exe) then it works fine. Which means, I can put A.dll in a sub directory, but the B.dll needs to be in the original directory.
Is there any way in which I can keep both DLLs in the sub directory?
Add a <probing>
element in your app.config:
http://msdn.microsoft.com/en-us/library/823z9h8w.aspx
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
这篇关于从另一个dll引用一个DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!