ReflectionOnlyAssemblyLoad and binding policy

I discussed ReflectionOnlyAssemblyLoad in detail here:

ReflectionOnlyAssemblyLoad explicitly does not apply any binding policy. This is so that you can get the exact assembly you requested.

Depending on your scenario, you may need to apply binding policy before you call ReflectionOnlyAssemblyLoad.

For example, if you want to validate an assembly before you load it, you really want to apply binding policy to mimic the fusion runtime binding behavior.

You can use AppDomain.ApplyPolicy for this purpose. AppDomain.ApplyPolicy takes an assembly reference as a string, and return the post-policy assembly reference as another string.

In short, you want to subscribe to ReflectionOnlyAssemblyResolve event, and your event handler will probably look like the following:

    private Assembly MyReflectionOnlyResolveEventHandler(object sender, ResolveEventArgs args)


        return Assembly.ReflectionOnlyLoad(AppDomain.CurrentDomain.ApplyPolicy(args.Name));


Comments (0)

Skip to main content