gpt4 book ai didi

c# - 为什么在尝试 Assembly.ReflectionOnlyLoad 时没有执行 ReflectionOnlyAssemblyResolve?

转载 作者:太空狗 更新时间:2023-10-29 18:33:43 25 4
gpt4 key购买 nike

我正在尝试通过连接到 AppDomain.AssemblyResolveAppDomain.ReflectionOnlyAssemblyResolve 事件来加载一些模块。当我让前者工作时,我在后者上惨遭失败。我把我的问题归结为这个小程序:

public static class AssemblyLoader
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve +=
ReflectionOnlyAssemblyResolve;

// fails with FileNotFoundException
Assembly.ReflectionOnlyLoad("Foo");
}

public static Assembly ReflectionOnlyAssemblyResolve(object sender,
ResolveEventArgs args)
{
Trace.TraceInformation(
"Failed resolving Assembly {0} for reflection", args.Name);

return null;
}
}

尝试 Assembly.ReflectionOnlyLoad 时,运行此程序失败并出现 FileNotFoundException,但它不会调用 ReflectionOnlyAssemblyResolve 处理程序。我在那里很困惑。

有没有人知道这可能是什么根本原因以及如何让它发挥作用?

谢谢!

最佳答案

ReflectionOnlyAssemblyResolve 事件似乎只用于解析依赖项,而不是顶级程序集,如下所示:

http://codeidol.com/csharp/net-framework/Assemblies,-Loading,-and-Deployment/Assembly-Loading/

在这里:

http://blogs.msdn.com/junfeng/archive/2004/08/24/219691.aspx

关于c# - 为什么在尝试 Assembly.ReflectionOnlyLoad 时没有执行 ReflectionOnlyAssemblyResolve?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/570117/

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