tags:

views:

42

answers:

1

If a .Net exe has a normal reference to a .Net assembly, will it load the assembly immediately when the exe is loaded, or will it wait until a class from the referenced assembly is used?

+1  A: 

Assemblies are loaded dynamically as they are needed. This code snippet shows how you can log assemblies as they are loaded:

    private static void InitializeAssemblyMonitor()
    {
        // Register for load event first
        AppDomain.CurrentDomain.AssemblyLoad +=
            delegate( object sender, AssemblyLoadEventArgs e )
            {
                LogAssembly( e.LoadedAssembly );
            };

        // Now log any assemblies that are already loaded
        foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
            LogAssembly( assembly );
    }
David Lynch