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.
Open the modules window from the menu Debug → Windows → Modules
Find the module to decompile, right-click on it and select "Decompile Source to Symbol File"
You should now be able to step into the code
Optional: Show the source files into the Solution Explorer
You may need to enable "Show miscellaneous files in Solution Explorer" in the VS settings.
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!
- View and edit the Tab Order of Windows Forms Controls
- Comparing files using Visual Studio
- Visual Studio Tips and tricks: Clipboard history
- Visual Studio Tips and tricks: Open recently closed files
- Visual Studio Tips and tricks: Multi-line and multi-cursor editing
- Visual Studio Tips and tricks: Extend/Reduce selection
- Visual Studio Tips and tricks: Undock/Re-dock a tool window
- Visual Studio Tips and tricks: Regex editing
- Visual Studio Tips and tricks: Find the current opened file in the solution explorer
- Visual Studio Tips and tricks: Default startup project
- Visual Studio Tips and tricks: Open the documentation of a symbol
- Visual Studio Tips and tricks: Paste as JSON
- Visual Studio Tips and tricks: Add project reference using drag & drop
- Visualizing the code coverage results from Azure Pipelines in Visual Studio
- Debugging a .NET assembly without the source code with Visual Studio (this post)
- Visual Studio Tips and tricks: Subword navigation
Do you have a question or a suggestion about this post? Contact me!