Debugging a .NET assembly without the source code with Visual Studio

  • Gérald Barré

This post is part of the series 'Visual Studio Tips and Tricks'. Be sure to check out the rest of the blog posts of the series!

When using an external closed-source library, it can sometimes be useful to understand how it works and debug it like if it were part of your solution.

To display the source code of a DLL when debugging, Visual Studio relies on PDB files (Symbol files) to link compiled code to source code. This means Visual Studio needs to find the PDB file and the .cs files. Visual Studio can load these files either from the local disk or from a symbol server. The problem with closed-source assemblies is that you don't have access to the source code. In this case, Visual Studio cannot get the code from your local disk or a remote server. Thus, you cannot step into the code of this DLL.

Starting with Visual Studio 2019 16.5, you can generate a PDB and the source files by decompiling the assembly. Visual Studio relies on ILSpy for decompiling the DLLs. Decompiling code comes with limitations. For instance, you cannot get the original comments nor variable names. Also, some code may be more complicated to read than in the original code because the decompiler doesn't recognize some patterns. Also, DLLs may be obfuscated, making them harder to decompile.

  1. Open the modules window from the menu Debug → Windows → Modules

  2. Find the module to decompile, right-click on it and select "Decompile Source to Symbol File"

  3. You should now be able to step into the code

  4. Optional: Show the source files into the Solution Explorer

    You may need to enable "Show miscellaneous files in Solution Explorer" in the VS settings.

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee