我正在尝试通过挂钩AppDomain.AssemblyResolve
和AppDomain.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;
}
}
FileNotFoundException
尝试运行此程序失败Assembly.ReflectionOnlyLoad
,但它不调用 ReflectionOnlyAssemblyResolve 处理程序。我很困惑。
有谁知道这可能是什么根本原因以及如何让它发挥作用?
谢谢!