LoadFrom 和上下文
我通过 Assembly.LoadFrom
加载存储在应用程序基本路径之外的程序集 (A);我加载的程序集引用同一目录中的另一个 .net 程序集 (B)。
当我尝试使用 A 程序集的某些方法时,Fusion 日志显示系统正在尝试从应用程序基目录而不是 A.dll 的父目录加载 B.dll。
我向 AppDomain.CurrentDomain.AssemblyResolve
添加了一个侦听器,该侦听器由发送者 AppDomain
调用,消息显示“没有上下文策略。”,并且 ResolveEventArgs.RequestingAssembly
属性设置为 null
。
LoadFrom
不应该允许在其父目录中搜索程序集的依赖项吗?
I am loading through Assembly.LoadFrom
an assembly (A) which is stored outside of the application base path; the assembly I load references another .net assembly (B) in the same directory.
When I try to use some methods of the A assembly, Fusion logs reveal that the system is trying to load B.dll from the application base directory rather than the parent directory of A.dll.
I added a listener to AppDomain.CurrentDomain.AssemblyResolve
, which is invoked with the sender AppDomain
having a message saying "There are no context policies.", and the ResolveEventArgs.RequestingAssembly
property set to null
.
Shouldn't LoadFrom
allow searching for an assembly's dependencies in its parent directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,我认为应该如此,但 leppie 是正确的,但事实并非如此。以下是有关程序集探测序列的详细 MSDN 文章。我曾多次遇到完全相同的问题,而使用 AssemblyResolve 事件是唯一的方法。
Yes, I think it should but leppie is correct, it doesn't. Here is a detailed MSDN article about the assembly probing sequence. There have been several times where I had the exact same issue and using the AssemblyResolve event is the only way.
嗯,其实应该的!确实如此。请参阅:
虽然 CLR 仍然尝试使用 GAC 和 appbase 目录解决程序集 (A) 的依赖关系,但它也会在文件夹中查找(A) 是从 加载的。
Well, actually it should! And it does. See:
An while CLR still tries to resolve dependencies of assembly (A) using GAC and appbase directory, it will also look in the folder (A) was loaded from.