是否可以在一个应用程序域中保存两个相同的.NET DLL? [英] Is it possible to hold two same .NET DLLs in one app domain?

查看:72
本文介绍了是否可以在一个应用程序域中保存两个相同的.NET DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

有一个进程在进程启动时加载了一个.NET DLL(比如foo.dll)。在另一个文件夹(比如说FooFolder)中,我得到了一个完全相同的foo.dll(同名,相同版本和相同的公共令牌)。我知道如果我使用Assembly.LoadFrom()加载FoolFolder / foo.dll,加载器将不会加载FoolFolder / foo.dll,并且当前域中只有一个foo.dll。

但是如果我使用Assembly.LoadFile()来加载FoolFolder / foo.dll,则DLL已成功加载,但是当我尝试在FoolFolder / foo.dll中执行代码时,我将无法加载log4net .DLL。 (foo.dll引用log4net.dll)。



问题:

是否有任何加载方法在一个应用程序域中成功完全相同的DLL?或者在.NET平台上是不可能的?

Problem:
There is a process that had loaded a .NET DLL(say foo.dll) when the process start up. In another folder(say FooFolder), I got an exactly same foo.dll (same name, same version and same public token). I know if I use Assembly.LoadFrom() to load the FoolFolder/foo.dll, the FoolFolder/foo.dll will not be loaded by loader and there is only one foo.dll in the current domain.
However if I use Assembly.LoadFile() to load FoolFolder/foo.dll, the DLL was loaded successfully, but when I try to execute the code in FoolFolder/foo.dll, I will get exception of could not load "log4net.dll". (foo.dll reference the log4net.dll).

Question:
Is there any approach to load exactly same DLL in one app domain successfully? or it is impossible in .NET platform?

推荐答案

我相信你不需要做任何这样的事情。您遇到的问题是您的代码无法找到log4net.dll。要么实现不正确,要么文件夹中的所有dll(log4net.dll)不可用。
I believe you don't need to do any such thing. The problem you are facing is that your code is unable to locate log4net.dll. Either the implementation is not correct or else the said dll (log4net.dll) is unavilable in the folder.


1)为什么在两个实例中有foo.dll?

2)你可以在可执行文件中嵌入另一个assambly,是你想要的。请参阅: ILMerge [ ^ ]

3)咨询MSDN [ ^ ],并查看.net如何定位assamblies。 Eslecially this one: http://msdn.microsoft.com/en-us /library/15hyw9x3(v=vs.110).aspx [ ^ ]。请注意,您可以使用日志和日志查看器来跟踪分辨率(请参阅: http://msdn.microsoft.com/en-us/library/e74a18c4(v = vs.110).aspx [ ^ ] 9。
1) Why do you have foo.dll in two instances?
2) You can embed another assambly in the executable, is you want. See: ILMerge[^]
3) Consult MSDN[^], and see how .net locates assamblies. Eslecially this one: http://msdn.microsoft.com/en-us/library/15hyw9x3(v=vs.110).aspx[^]. Please note, that there is a log and a log viewer you can use to track resolution (see: http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx[^]9.


这篇关于是否可以在一个应用程序域中保存两个相同的.NET DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆