gpt4 book ai didi

c# - 当程序集路径和版本不同时,Assembly.LoadFrom 返回相同的程序集

转载 作者:行者123 更新时间:2023-11-30 14:01:19 28 4
gpt4 key购买 nike

想象一下这个场景:

var ass1 = Assembly.LoadFrom(@"C:\Work\3.59\assembly1.dll");
var ass2 = Assembly.LoadFrom(@"C:\Work\3.60\assembly1.dll");

Debug.Assert(ass1 != ass2);

上述断言失败。似乎第二个调用返回第一个程序集,即使上面的两个程序集具有不同的版本和位置。

程序集未命名且无法签名。

有没有办法强制框架将它们加载到相同的上下文和域中?

最佳答案

改用 Assembly.LoadFile(path)

来自 MSDN

The LoadFrom method has the following disadvantages. Consider using Load instead.

If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

来自 CLR developer Suzanne Cook's blog :

If the assembly is not strongly-named, then the version is ignored for binding. But, if it is strongly-named, the entire version in the assembly reference needs to match the found assembly.

关于c# - 当程序集路径和版本不同时,Assembly.LoadFrom 返回相同的程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8535238/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com