tags:

views:

103

answers:

4

The depends.exe tool can walk thru all the dll's that the executable depends to, but if the DLL is loaded by the Assembly class dynamically at runtime, how can I see the already loaded DLLs(assemblies)?

+5  A: 

As a snapshot:

AppDomain.CurrentDomain.GetAssemblies()

As they happen:

AppDomain.CurrentDomain.AssemblyLoad

Something like:

static void Main()
{
    AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoad;
    LogCurrent("before");
    AnotherMethod();
    LogCurrent("after");
}
static void AnotherMethod()
{
    // to force stuff to happen
    new System.Data.SqlClient.SqlCommand().Dispose(); 
}
static void LogCurrent(string caption)
{
    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
    {
        Console.WriteLine(caption + ": " + asm.FullName);
    }
}

static void AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
    Console.WriteLine("Loaded: " + args.LoadedAssembly.FullName);
}
Marc Gravell
Thanks. But what I want is an external tools like depends.exe to view the loaded assemblies.
Bin Chen
If it is loading the dll at runtime, then it could be getting the string from anywhere. The only way to monitor it is *at* runtime. You could use windbg/sos, and attach to the process?
Marc Gravell
WinDbg must be the most convenient way. You can simply use "lm" to list all modules, both native and managed.
Lex Li
+3  A: 

Assuming you're not messing with AppDomains:

AppDomain.CurrentDomain.GetAssemblies();
pyrochild
+1  A: 

You say you are looking for external tool ? Try WinDbg with SOS debugging extension; http://msdn.microsoft.com/en-us/library/bb190764.aspx.

There are other tools that might be easier to use that provide the same level of detail. I think the folks over at JetBrains have one ( Resharper )

dlargen
+1  A: 

fuslogw can help with this, it has an option for monitoring all assembly bindings http://msdn.microsoft.com/en-us/library/e74a18c4%28VS.71%29.aspx

alexm