How do I determine the dependencies of a .NET application? Does Dependency Walker work with managed apps? I've downloaded the latest and tried profiling the app, but it just exits without much of an explanation. If it doesn't work with .NET, then is there some other tool that would help me debug a run-time DLL loading issue?
12 Answers
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 think you missed a little of that URL - the .aspx got put in the link text. I managed to find it though. Commented Oct 23, 2008 at 0:33
-
oh... yeah the markdown control eats brackets in URL's, and unfortunately MSDN puts (VS80) in all it's url's :-( Commented Oct 27, 2008 at 4:12
-
47Note that as of early 2011, .NET Reflector is no longer free. The open source ILSpy project is very similar.– yoyoCommented Feb 21, 2012 at 5:09
-
2Assembly Binding Log View v4.0.30319.1 is utterly unusable. Log entries are not displayed in chronological order and you cannot sort them. It displays paths which do not fit in the viewer and you cannot resize it. It's a complete waste of time.– NeutrinoCommented Aug 28, 2013 at 14:42
-
dependencywalker.com You should include urls of things you mention, esp. if they work.– toddmoCommented Nov 15, 2013 at 17:17
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
-
Can it work on the C# files or Razor views also? I am creating a sub project by exporting some of views and a controller from a mvc project at run time. And I want to know what dependencies are required by these Views and the controller so that I can copy these dependencies also at run time to make the sub-project publishable as a separate web project on IIS.– RupendraCommented Jun 21, 2017 at 8:49
-
1Excellent tool, simple to use, easy to understand. Thank you!– HowardCommented Jun 30, 2022 at 4:58
Open the assembly file in ILDASM and look @ the .assembly extern in the MANIFEST
-
1Can I see the version of the dependent assemblies this way too? I only see the dependency name, not it's version as well. Commented Mar 10, 2016 at 19:21
-
Actually, yes, I can see the version of the dependent assemblies this way too, upon clicking "M A N I F E S T" Commented Mar 10, 2016 at 19:26
-
1I prefer this one - don't need to download any additional utilities if you're working in a dev environment Commented Feb 3, 2017 at 19:48
-
When debugging a third party app crash, how to install only ildasm on customer of?– realteboCommented Jun 15, 2018 at 11:58
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()
-
18For debugging purposes, it's more convenient to do this via PowerShell:
[Reflection.Assembly]::LoadFile('C:\absolute\path\to\my.dll').GetReferencedAssemblies()
. Has the nice advantage of not downloading or hunting obscure Windows locations for tools. +1– jpmc26Commented Aug 12, 2016 at 20:59 -
5correct me if im wrong but this will just give you the same error that your application with a missing dependency gives so is not very useful– jk.Commented Aug 31, 2016 at 10:51
-
This works only when the assembly is loaded into an AppDomain. Assemblies loaded for Reflection return a null set. Commented Dec 19, 2019 at 6:28
To browse .NET code dependencies, you can use the capabilities of the tool NDepend. The tool proposes:
- a dependency graph
- a dependency matrix,
- and also some C# LINQ queries can be edited (or generated) to browse dependencies.
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
-
3Patrick should probably have mentioned he's the author of that fantastic tool ;). It's really worth checking out. +1 for writing it! Commented Nov 21, 2008 at 9:30
-
1Hey, I just noticed this myself. I enjoy reading his blog posts - I'll have to try out NDepend! Commented Dec 17, 2008 at 21:19
-
3@MitchWheat -- name checks out haha, "Patrick from NDepend team" Commented Apr 27, 2017 at 22:25
-
Can I use with VStudio? To debug app crashes of third party apps on not my pc– realteboCommented Jun 15, 2018 at 11:59
It's funny I had a similar issue and didn't find anything suitable and was aware of good old Dependency Walker, so in the end I wrote one myself.
This deals with .NET specifically and will show what references an assembly has (and missing) recursively. It'll also shows native library dependencies.
It's free (for personal use) and is available here for anyone interested.
Feedback welcome.
-
Please add drag and drop support for opening assemblies. It would also be nice if XCOPY deployment was available, as well as source code.– gigaplexCommented Dec 21, 2015 at 0:02
-
I just noticed that the website doesn't have any obvious links to the section where there are two editions, and the free one is for non-commercial use. I accidentally stumbled on this by finding the "Upgrade to Professional" option in the Help menu. There should be a notice on the download page saying that it's not free for commercial use.– gigaplexCommented Dec 21, 2015 at 0:08
-
@gigaplex I'll take note of both of these thanks, I'll see what I can do.– LloydCommented Dec 21, 2015 at 11:41
-
1Shiftclick to open a tree and all subitems would be useful as well.– T.SCommented Jul 7, 2017 at 9:02
-
1
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.
Example usage:
monodis --assemblyref somefile.exe
Example output (.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
Example output (.dll):
$ 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.
Providing a Solution for Updated .Net Versions
This may not have been the case when the OP asked the question, but there is currently a built-in dotnet
command for listing the package dependencies within a solution:
PS C:\foo> dotnet list package
Project 'foo' has the following package references
[net5.0]:
Top-level Package Requested Resolved
... ... ...
More information can be found on the Microsoft docs website: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-list-package
ChkAsm will show you all the dependencies of a particular assembly at once, including the versions, and easily let you search for assemblies in the list. Works much better for this purpose than ILSpy (http://ilspy.net/), which is what I used to use for this task.
-
2As of 2019 that site appears to be some kind of sketchy-looking blog... Commented Mar 15, 2019 at 14:27
-
@McGuireV10 So it is. That's unfortunate. And a quick google turns up no hits for that app anymore. Commented Mar 16, 2019 at 15:34
Try compiling your .NET assembly with the option --staticlink:"Namespace.Assembly"
. This forces the compiler to pull in all the dependencies at compile time. If it comes across a dependency that's not referenced it will give a warning or error message usually with the name of that assembly.
Namespace.Assembly
is the assembly you suspect as having the dependency problem. Typically just statically linking this assembly will reference all dependencies transitively.
At my company we use "Assembly Information" by Ashutosh Bhawasinka. It is implemented as a shell extension, so you just right-click on the *.dll file and you get the information. You can see a dependency tree OR get a flat list of all the dependencies. What I like about this tool is that it also shows the Public Key Token which is a good way to check for conflicts. Here is an example of the flat list output of one of my company's assemblies:
ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=484f84ea1d6cf4da
mscorlib, Culture=neutral, PublicKeyToken=b77a5c561934e089
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
We compiled in .Net Framework 4.0, so you can see that with the version on mscorlib; we are also referencing SharpZipLib which was compiled for .Net Framework 2.0 so we see that dependency also. Nice.
The only problem is that the utility was posted on CodePlex which was shut down. Thankfully, we kept a copy of the original files. I can't find it anywhere else on the web, so I've decided to post it here for anyone to get a copy of (looks like we only saved the 64 bit version):
http://riosoftware.com/temp/pub/Assembly%20Information%20for%2064bit%20Operating%20System.zip