I need to hookup an AssemblyResolve event on my created AppDomain when I've set DisallowApplicationBaseProbing = true. The reason I'm doing this is to force the runtime to call the AssemblyResolve event it needs to resolve an assembly, instead of probing first. This way, another developer can't just stick MyDllName.dll in the ApplicationBase directory and override the assembly I wanted to load in the AssemblyResolve event.
The issue with doing this is the following...
class Program
{
static void Main()
{
AppDomainSetup ads = new AppDomainSetup();
ads.DisallowApplicationBaseProbing = true;
AppDomain appDomain = AppDomain.CreateDomain("SomeDomain", null, ads);
appDomain.AssemblyResolve += OnAssemblyResolve;
appDomain.DoCallBack(target);
}
static System.Reflection.Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
Console.WriteLine("Hello");
return null;
}
private static void target()
{
Console.WriteLine(AppDomain.CurrentDomain);
}
}
The code never gets past the += OnAssemblyResolve line.
When the code tries to execute, the new app domain tries to resolve the assembly I'm executing in. Because DisallowApplicationBaseProbing = true, it has no idea where to find this assembly. I have a chicken & egg problem it seems. It needs to resolve my assembly to hookup the assembly resolver but needs the assembly resolver to resolve my assembly.
Thanks for any and all help.
-Mike
Console.WriteLine("Hello");
? If yes, maybe you should implement a logic that is able to resolve assemblies. I stumbled into this question, because I have quite the same problem. If I find a solution, I'll post an answer. – No answer