If you have dealt with assembly loading, chances are you have asked this question:


How do I know which assembly CLR will really load if I ask it to load some assembly?


In .Net framework 1.0 and 1.1, there is really no good way other than load the assembly.


In Whidbey, we introduce AppDomain.ApplyPolicy. It takes an assembly identity string as input, evaluates binding policy, and returns the post policy assembly identity.


It does not tell you which file CLR will load. But at least you are confident about the assembly identity.


It is an instance method on AppDomain class. So you are able to evaluate the policy on any appdomain.

Comments (4)

  1. David Levine says:

    Just to be clear, this cannot be used to identify which directory an assembly will be loaded from, but it can tell which assembly identity (i.e. 4 part name) will be loaded, taking into account all binding redirects in effect for an appdomain.

    For example, assuming the assemblies are signed, if there are two copies of foo.dll, v1.1 in different directories below the appbase, it wont tell you which directory it will be loaded from, but it will tell you that it is assembly foo, v1.1 and not, say foo, v2.3.

    Is there any means of determining which load context an assembly is loaded into?

  2. That is correct. This will only tell you the post policy assembly identity. But it can’t tell you were the assembly will be loaded. The second one is determined by too many factors, the only good way to determine that is to load it. But you should already has a pretty good heuristics from the standard probing rules.

    As for the second question, no there is no means of determine which load context an assembly is loaded into. Several reasons,

    1. Load context is implementation artifact. Today it is not exposed anywhere. To expose this we have to expose load context. And exposing implementation detail is not something we want to introduce.

    2. This is not a high priority ask from customers, comparing with other asks.

    I know you are disappointed. Believe me I did ask the team to consider this and it is turned down. Not every request can be satisfied given the limited resource and time we have.

Skip to main content