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)?
            Asked
            
        
        
            Active
            
        
            Viewed 3,558 times
        
    2
            
            
        - 
                    1Does this answer your question? [How do you loop through currently loaded assemblies?](https://stackoverflow.com/questions/383686/how-do-you-loop-through-currently-loaded-assemblies) – StayOnTarget Feb 03 '20 at 16:26
 
4 Answers
6
            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
        
- 1,026,079
 - 266
 - 2,566
 - 2,900
 
- 
                    Thanks. But what I want is an external tools like depends.exe to view the loaded assemblies. – Bin Chen Dec 11 '09 at 05:36
 - 
                    1If 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 Dec 11 '09 at 06:12
 - 
                    1WinDbg must be the most convenient way. You can simply use "lm" to list all modules, both native and managed. – Lex Li Dec 11 '09 at 06:35
 - 
                    Should `AssemblyLoad(object sender, AssemblyLoadEventArgs args)` return `Assembly` and *not* be of `void`? – rasx Jun 08 '12 at 00:22
 
4
            
            
        Assuming you're not messing with AppDomains:
AppDomain.CurrentDomain.GetAssemblies();
        bsneeze
        
- 4,369
 - 25
 - 20
 
1
            
            
        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
        
- 11
 - 1
 
1
            
            
        fuslogw can help with this, it has an option for monitoring all assembly bindings http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx
        oldUser
        
- 243
 - 2
 - 12