且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我复制的DLL程序启动后,在运行时加载组件失败

更新时间:2023-12-06 15:40:04

功能,不是一个错误。这是一个DLL地狱应对措施。手术词是加载上下文,搜索苏珊娜·库克的博客,以更多地了解词组它。概括地说,CLR的记忆previous尝试加载程序集。首先,它会记录成功的绑定,并保证了的确切的相同的组件将被再次加载,即使磁盘内容发生了变化。可以毫无疑问,看到了好处,突然得到的另一个的组件,几乎都是灾难性的。

Feature, not a bug. It is a DLL Hell counter-measure. The operative term is 'loading context', search Suzanne Cook's blog for the phrase to learn more about it. In a nutshell, the CLR memorizes previous attempts to load an assembly. First and foremost, it records successful bindings and guarantees that the exact same assembly will be loaded again, even if the disk contents have changed. You can no doubt see the benefit of that, suddenly getting another assembly is almost always disastrous.

同样是如此的没有的程序集绑定。它会记住那些为好,出于同样的原因,它会辜负他们的未来。有没有文档化的方式来重新装载情况下,我知道了。 Assembly.LoadFile()加载组件没有加载上下文。但是,这会导致其他的一系列问题,你真的不想使用它。

The same is true for failed assembly binds. It memorizes those as well, for much the same reason, it will fail them in the future. There is no documented way to reset the loading context that I know of. Assembly.LoadFile() loads assemblies without a loading context. But that causes a whole range of other problems, you really don't want to use it.