DLL loading sequence at service start

How can we track the assembly loading sequence when starting a Windows service?

For instance. When we start the service, it loads all the reference assemblies and their dependencies; what I want to do is which assemblies (OS, CLR, etc.) are loaded before the service actually starts.

+3
source share
1 answer

You can use the event AssemblyLoadto AppDomain.CurrentDomainto do this.

static void Main(string[] args)
{
    AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);

    Assembly.Load("ICSharpCode.SharpZipLib");

    Console.WriteLine("Completed loading");

    /*
     * This produced:

       Loaded assembly C:\Documents and Settings\...\ConsoleApplication2\bin\Debug\ICSharpCode.SharpZipLib.dll
       Completed loading
     */
}

static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
    Console.WriteLine("Loaded assembly " + args.LoadedAssembly.Location);
}

Please note that this will only work for assemblies that have been downloaded since the event was added. mscorlib, for example, already loaded before the call Main, because for this you need to execute Main.

, , , , .

+2

Source: https://habr.com/ru/post/1774236/


All Articles