In .NET is there a way to enable Assembly.Load tracing?
-
03-07-2019 - |
Question
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.
Solution
Get the AppDomain for your application and attach to the AssemblyLoad event.
Example (C#):
AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
OTHER TIPS
Fusion Log Viewer is your friend.
[edit] Actually this might be too over the top, the AssemblyResolve event is good too[edit]
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'