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 t
With lots of experiments I got the following working:
internal class AssemblyResolver : MarshalByRefObject
{
static internal void Register(AppDomain domain)
{
AssemblyResolver resolver =
domain.CreateInstanceFromAndUnwrap(
Assembly.GetExecutingAssembly().Location,
typeof(AssemblyResolver).FullName) as AssemblyResolver;
resolver.RegisterDomain(domain);
}
private void RegisterDomain(AppDomain domain)
{
domain.AssemblyResolve += ResolveAssembly;
domain.AssemblyLoad += LoadAssembly;
}
private Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
// implement assembly resolving here
return null;
}
private void LoadAssembly(object sender, AssemblyLoadEventArgs args)
{
// implement assembly loading here
}
}
The domain is created like this:
AppDomainSetup setupInfo = AppDomain.CurrentDomain.SetupInformation;
setupInfo.DisallowApplicationBaseProbing = true;
domain = AppDomain.CreateDomain("Domain name. ", null, setupInfo);
AssemblyResolver.Register(domain);
Sorry, I can't share the code for resolving and loading the assemblies. Firstly, it doesn't work yet. Secondly, it will be too much and too specific to share with the general public in this context.
I'll be bootstrapping an object structure that is serialized alongside the assemblies required for deserialization from a single file. For this, I really deserve going straight to .dll hell.