If we call AppDomain.CurrentDomain inside codes loaded into separate domains, what domain reference we’ll get ? The main domain reference or the domain reference where the current code is loaded ?
Suppose, we’re loading assemblies inside a domain, and we need to probe assemblies in the event AssemblyResolve: We can use AppDomain.CurrentDomain to get the current domain reference or we’ll need to create a way to pass the domain reference to it ?
AppDomain.CurrentDomain returns the domain in which your code is running. Yes, using it in an AssemblyResolve event handler is always safe and correct. That event is specific to each AppDomain and will be fired when the AppDomain needs an assembly it cannot otherwise find itself.
The event handler’s
eargument is of type ResolveEventArgs. Which only tells you the name of the assembly, not the AppDomain that needs it. It is assumed you already know. Use CurrentDomain if you forgot.Do favor using AppDomainSetup so you don’t need this event handler.