how to locate dll in native c++ world / dotnet world?

DLL加载顺序
本文探讨了在native C++和.NET环境中DLL及其依赖项的加载顺序。对于C++,讨论了Dynamic-Link Library Search Order并提出了一个关于自定义文件夹中DLL搜索的问题。对于.NET,则详细介绍了CLR如何定位程序集,包括GAC的使用和个人程序集的位置。

总结:

1. 对于native c++ world来说,Dynamic-Link Library Search Order 说的很清楚了。就是还有一个疑问:如果在任意目录建立一新folder,把一个application需要的plugin之类的dll及dependency dlls都放在里面,在load这个plugin需要的dependency dlls时 (If a DLL with dependencies is loaded by specifying a full path, the system searches for the DLL's dependent DLLs as if they were loaded with just their module names.)这个新的folder会被search到吗?

2. 对于dotnet world,首先理解有两个application级的文件:app.exe.manifest, app.exe.config。 然后,关于runtime CLR如何locate assembly,这篇How the Runtime Locates Assemblies 是全面的介绍。The simple version is that the GAC is searched firstly, and then the app path tree. %PATH% is never used.  相关基础知识:

    1)In dotnet world, A private assembly is stored in the application’s directory and used by a single application. A share assembly can be used by multiple applications and is stored in the Global assembly cache, a repository of assemblies maintained by the .Net Framework.

    2)GAC 和sidebyside的区别,本blog里有详细介绍。

    3)如果你确实需要把一个app的private assembly(一定程度上算,但绝对算不是放在GAC里的资格)搬出app path来放,MS还提供了一套机制来帮助你定位assembly成功:AssemblyResolver。具体介绍,参见本blog AssemblyResolver。 

    4)use Assembly Binding Log Viewer (Fuslogvw.exe) to debug any assembly loading problems.

 

参考: In what order are locations searched to load referenced DLLs?

转载于:https://www.cnblogs.com/taoxu0903/archive/2010/12/16/1908694.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值