Dependency Walker can do this for you: It displays a tree of all dependencies and their dependencies. Show activity on this post. Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical tree diagram of all dependent modules.
A dependency is an object that another object depends on. Dependency Injection (or inversion) is basically providing the objects that an object needs, instead of having it construct the objects themselves. It is a useful technique that makes testing easier, as it allows you to mock the dependencies.
Dependency Walker (Depends), which can be launched via Process Explorer, no longer works well in Windows 10 as of at least build 10.0. 19043 (21H1 May 2021 update). The UI can hang for several minutes while (e.g.) enumerating Notepad's dependencies. It may be time to have Process Explorer link to an alternative.
Dependency walker works on normal win32 binaries. All .NET dll's and exe's have a small stub header part which makes them look like normal binaries, but all it basically says is "load the CLR" - so that's all that dependency walker will tell you.
To see which things your .NET app actually relies on, you can use the tremendously excellent .NET reflector from Red Gate. (EDIT: Note that .NET Reflector is now a paid product. ILSpy is free and open source and very similar.)
Load your DLL into it, right click, and chose 'Analyze' - you'll then see a "Depends On" item which will show you all the other dll's (and methods inside those dll's) that it needs.
It can sometimes get trickier though, in that your app depends on X dll, and X dll is present, but for whatever reason can't be loaded or located at runtime.
To troubleshoot those kinds of issues, Microsoft have an Assembly Binding Log Viewer which can show you what's going on at runtime
I find the small utility AsmSpy an invaluable tool to for resolving issues with loading assemblies. It lists all assembly references of managed assemblies including assembly versions.
Run it in a command prompt in the directory of the .dll
with the following arguments:
asmspy . all
Install it quickly with Chocolatey:
choco install asmspy
Open the assembly file in ILDASM and look @ the .assembly extern in the MANIFEST
You don't need to download and install shareware apps or tools. You can do it programitically from .NET using Assembly.GetReferencedAssemblies()
Assembly.LoadFile(@"app").GetReferencedAssemblies()
To browse .NET code dependencies, you can use the capabilities of the tool NDepend. The tool proposes:
For example such query can look like:
from m in Methods
let depth = m.DepthOfIsUsing("NHibernate.NHibernateUtil.Entity(Type)")
where depth >= 0 && m.IsUsing("System.IDisposable")
orderby depth
select new { m, depth }
And its result looks like: (notice the code metric depth, 1 is for direct callers, 2 for callers of direct callers...) (notice also the Export to Graph button to export the query result to a Call Graph)
The dependency graph looks like:
The dependency matrix looks like:
The dependency matrix is de-facto less intuitive than the graph, but it is more suited to browse complex sections of code like:
Disclaimer: I work for NDepend
If you are using the Mono toolchain, you can use the monodis
utility with the --assemblyref
argument to list the dependencies of a .NET assembly. This will work on both .exe
and .dll
files.
monodis --assemblyref somefile.exe
$ monodis --assemblyref monop.exe
AssemblyRef Table
1: Version=4.0.0.0
Name=System
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
2: Version=4.0.0.0
Name=mscorlib
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
$ monodis --assemblyref Mono.CSharp.dll
AssemblyRef Table
1: Version=4.0.0.0
Name=mscorlib
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
2: Version=4.0.0.0
Name=System.Core
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
3: Version=4.0.0.0
Name=System
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
4: Version=4.0.0.0
Name=System.Xml
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
Enable assembly binding logging set the registry value EnableLog in HKLM\Software\Microsoft\Fusion to 1. Note that you have to restart your application (use iisreset) for the changes to have any effect.
Tip: Remember to turn off fusion logging when you are done since there is a performance penalty to have it turned on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With