views:

579

answers:

3

In .NET is there a way to enable Assembly.Load tracing? I know while running under the debugger it gives you a nice message like "Loaded 'assembly X'" but I want to get a log of the assembly loads of my running application outside the debugger, preferably intermingled with my Debug/Trace log messages.

I'm tracing out various things in my application and I basically want to know what action triggered a particular assembly to be loaded.

+8  A: 

Get the AppDomain for your application and attach to the AssemblyLoad event.

Example (C#):

AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
Jeff Yates
+4  A: 

Fusion Log Viewer is your friend.

[edit] Actually this might be too over the top, the AssemblyResolve event is good too[edit]

leppie
I prefer to use FusLogView because I don't have to modify my code if I am just diagnosing some assembly load problems.
Sergio Acosta
This is good for general diagnostics but for my particular scenario I thing the AssemblyLoad event is going to get me where I need to be.
Wes Haggard
Be warned, it might behave differently on Mono :)
leppie
+1  A: 

MS Visual Studio has this functionality built in.

Select 'Module Load Messages' from the context menu of the output window in MS Visual Studio and it will display something like:

Loaded 'C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
Loaded 'C:\projects\trunk\bin\Tester.exe', Symbols loaded.
Loaded 'C:\projects\trunk\bin\log4net.dll'
Thomas Bratt