Share via


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.

Comments

  • Anonymous
    December 20, 2005
    Do you have any advice on preventing unnecessary resource probing for OBJECT-tag hosted managed controls in Internet Explorer? These HTTP requests are obviously very expensive. At present I'm placing a zero-length file where the first probe attempt is made.
  • Anonymous
    December 20, 2005
    Max,

    I'll ask our resource guys to see if there is any guideline on this.
  • Anonymous
    December 21, 2005
    Max,

    please see http://blogs.msdn.com/bclteam/archive/2005/10/11/479330.aspx.
  • Anonymous
    December 21, 2005
    Splendid, thanks Junfeng.
  • Anonymous
    December 23, 2005
    wow
  • Anonymous
    December 28, 2005
    The comment has been removed
  • Anonymous
    December 30, 2005
    Alex,

    Can you show an example?
  • Anonymous
    March 06, 2006
    I'm sorry, may I provide a sample now or is this thread already closed? Thank you.
  • Anonymous
    March 06, 2006
    Please do.
  • Anonymous
    March 10, 2006
    I have a question I guess is related to the problem.

    I create additional AppDomain and subscribe for AsemblyResolve event. The class that provides handler is derived from MarshalByRefObject.

    1. Handler method (instance) private: an exception is raised while an assembly is being resolved.
    2. Handler method (instance) public: the same exception.
    3. Handler method static public: everything is fine.

    I have to make some bad architecture moves to support static handler method.
    Is there any way to make it work with instance handler?


    Thank you
  • Anonymous
    March 10, 2006
    Here is the reply I get from the loader dev:

    "Is he trying to provide the resolve handler for one appdomain from another appdomain?
    Because if he is, I have bad news for him - subscribing to AssemblyResolve from another appdomain doesn't work as the result cannot be marshaled (Assembly class is not MarshalByRef).
    The reason (3) appears to work is because the static method is actually called in that additional appdomain not in the original one(it's been marshaled when subscribing to the event) so there is no actual appdomain transition there and our inability to marshal the Assembly object does not come into play.
    "
  • Anonymous
    March 12, 2006
    Thank you.

    I applyed SerializableAttribute (instead of inheritance from MarshalByRefObject) and it seems the resolving is working fine. Also an instance resolver method is used.

    May be there are drawbacks, but I've not found them yet.

    Thanks.
  • Anonymous
    May 29, 2009
    PingBack from http://paidsurveyshub.info/story.php?title=junfeng-zhang-s-windows-programming-notes-satellite-assembly-and