开发者

DLL loading sequence on Service startup

How can we trace the assembly loading sequence on windows service startup?

For example. When we start a service it loads all the reference assemblies and their dependencies; what i want to do is that which assembl开发者_如何学编程ies (OS, CLR or etc) are being loaded before actually starting the service.


You can use the AssemblyLoad event on AppDomain.CurrentDomain for 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);
}

Note that this will only work for assemblies that are loaded from the point you add the event. mscorlib for example is already loaded before the Main is called because you need this to be able to run Main.

Of course, if you create the domain yourself, you can add this event before the domain is started and you should see all the loaded assemblies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜