Domain Neutral Assemblies and AssemblyResolveEvent handler

Please read my blog domain neutral assemblies on background information.

 

We have learned that

 

The assembly can be shared, as long as all the available assemblies in the binding closure are the same in the two appdomains, and the missing assemblies in the binding closure are also the same.

The binding closure is evaluated by fusion.

 

But even if an assembly cannot be found by fusion, the application can still subscribe to AssemblyResolveEvent, and provide the assembly there.

 

That means the decision fusion makes isn’t necessary correct.

 

To fix this problem, for each assembly that cannot be found in the binding closure, loader will explicitly invoke the AssemblyResolveEvent handler if any. If the event handler returns an assembly, loader will refuse to share this assembly.

 

For AssemblyResolveEvent handler, this means the event handler can be called for assemblies that the application did not reference directly.