如何使用加载超过1个文件DLL
(( AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler() ))
这只是第一个起作用,而另一个不起作用?! 我需要加载两个DLL文件嵌入的资源,因此我可以在没有文件的情况下使用该应用程序!
public MainWindow()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
InitializeComponent();
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e)
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DS.WpfAnimatedGif.dll"))
{
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve2(object sender, ResolveEventArgs e)
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DS.Newtonsoft.Json.dll"))
{
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
答案 0 :(得分:0)
从第一个事件处理程序返回后,下一个事件处理程序将被忽略。
这是as per the documentation here:
如果为此事件注册了多个事件处理程序,则将依次调用事件处理程序,直到一个事件处理程序返回不为null的值为止。随后的事件处理程序将被忽略。