Hi Rainer,
AppDomain.AssemblyResolve will be fired when the resolution of an assembly
fails, that is when your application is missing any assembly. Note: .Net is
using delay assembly loading style, so if your main Exe is linking with
some class library assembly but did not use it yet, the .Net loader will
not try to resolve and load it yet. Below is a sample to demonstrate this:
//class library assembly
namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b;
}
}
}
//I created a .Net Winform project
//and use this class library assembly
//in the Button.Click event
private void button1_Click(object sender, EventArgs e)
{
ClassLibrary1.Class1.Add(3, 4);
}
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object
sender, ResolveEventArgs args)
{
MessageBox.Show(String.Format("Assembly {0} is missing", args.Name));
return null;
}
After I deleted the ClassLibrary1.dll in the Exe folder, I double-click the
exe to launch the application. Everything works well, the
CurrentDomain_AssemblyResolve is not fired. Then, when I click the button
in the form, the CurrentDomain_AssemblyResolve is fired and the CLR is
asking you for *help* to find the missing assembly.
You may give this a test to see if the behavior is consistent.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.