Satellite assembly and AssemblyResolve event

In .Net framework, CLR will not raise AssemblyResolve event for missing satellite assemblies (to be precise, Resource Manager asks CLR loader to not raise AssemblyResolve event if it can’t find a satellite assembly.). The reason is that Resource Manager has many by-design assembly loading failures. It will unnecessarily flood the AssemblyResolve event handler to raise AssemblyResolve event for every satellite assembly loading failure.

 

This brings up a question:

 

How to return satellite assembly for assemblies returned from AssemblyResolve event?

 

For example, we have the following deployment:

 

C:\MyApp\app.exe

C:\Others\myasm.dll

C:\Others\zh-cn\myasm.resource.dll

 

App.exe tries to load myasm.dll, which won’t be found in C:\MyApp. An AssemblyResolve handler is invoked, and myasm.dll is returned from C:\Others\myasm.dll. Now myasm.dll wants to use its zh-cn satellite assembly. Since the assembly won’t be found in C:\MyApp, and CLR won’t raise AssemblyResolve for the satellite assembly, how can we return the satellite assembly?

 

The answer is, use Assembly.LoadFrom in the AssemblyResolve handler to return myasm.dll.

 

When an assembly load is requested is in the LoadFrom context, CLR will probe the assembly in the parent assembly’s directory, in additional to the application base. Therefore, the satellite assembly in C:\others will be found by CLR automatically.