Assembly loading and AppDomain.AssemblyLoad Event

Assembly loading (Assembly.Load) is the process of loading an assembly reference. It starts with an assembly reference, and ends with a System.Reflection.Assembly instance that can be JITted and executed.




The following content is implementation detail. It is only applicable to CLR v2.0. And it may change in the future without notice.


The whole loading process can roughly be divided in several phases:


  1. Binding

    This is process of locating the file based on the assembly references. MSDN documents the process in detail here (

    This phase is performed by fusion.

    After binding returns, the file path of the assembly is returned to CLR loader.

  2. Mapping

    In this phase the file return from binding is mapped into the process. This is typically accomplished by calling LoadLibrary, and some pre-LoadLibrary and post-LoadLibrary processing.

  3. Deliver Events

    CLR Loader delivers profiler and debugger load events for the assembly, and raise AppDomain based events related to assembly load (including AppDomain.AssemblyLoad) event.

  4. Initialize the assembly

    Module constructors are run in this phase. Static data are also initialized.

After phase 4, managed code in the assembly can be executed.


As we can see, no managed code can be executed before AppDomain.AssemblyLoad event is delivered.  But unmanaged code may run during LoadLibrary if the assembly is MC++ assembly.


Comments (7)

  1. Hasani says:

    Is there a way for one to create his/her own module constructor?

  2. The only way I know is using ILAsm.

  3. Wojtek says:

    Is there any way to capture Assembly loading process and provide my own loader (i.e. to load assemblies from database)

  4. You can always subscribe AssemblyLoad event and return Assembly.Load(byte[]).

    On v2.0 you can use IHostAssemblyManager/IHostAssemblyStore. See MSDN for documentation.

  5. Eliane says:

    In my code I subscribed AssemblyLoad event, but when it is fired, the assembly is already loaded and, for instance, I can not update to the correct assembly… is there an event which happens before the assembly loading?

  6. Eliane says:

    AssemblyLoad event does not return Assembly.Load(byte[]), it is a Sub.

    Is there a way to unload the assembly, copy the correct assembly if necessary, and load the correct assembly in AssemblyLoad event?

  7. Sorry I had a type in my 1/18 comment. I meant AssemblyResolve event.

    No there is no event happens before the assembly loading. No there is no way to unload an assembly.