-->
When debugging a .NET application, you may find that you want to view source code that you don't have. For example, breaking on an exception or using the call stack to navigate to a source location.
- Yes, you can decompile the.exe file and get the source code in three ways as I know (and maybe possible in other ways too:) ) Here is a step by step way to.
- Delphi and CBuilder Decompiler is an easy-to use application which can help you to restore your lost source code. If you lose your Delphi or CBuilder project sources, but have an executable file, then this tool can rescue part of lost sources. Decompiler produces all project forms and data modules with all assigned properties and events.
Spices.Net Decompiler offers a productivity package for.NET software developers that is exceptional in the industry for ease of use and top of the range performance. Spices.Net Decompiler is a efficient and flexible tool, that converts.NET binaries (.EXE or.DLL) from binary format to a beautifully formatted, optimized and commented source.
Note
- Source code generation (decompilation) is only available for .NET applications and is based on the open source ILSpy project.
- Decompilation is only available in Visual Studio 2019 16.5 and later.
- Applying the SuppressIldasmAttribute attribute to an assembly or module prevents Visual Studio from attempting decompilation.
Generate source code
When you're debugging and no source code is available, Visual Studio shows the Source Not Found document, or if you don’t have symbols for the assembly, the No Symbols Loaded document. Both documents have a Decompile source code option that generates C# code for the current location. The generated C# code can then be used just like any other source code. You can view the code, inspect variables, set breakpoints, and so on.
No symbols loaded
The following illustration shows the No Symbols Loaded message.
Source not found
The following illustration shows the Source Not Found message.
Generate and embed sources for an assembly
In addition to generating source code for a specific location, you can generate all the source code for a given .NET assembly. To do this, go to the Modules window and from the context menu of a .NET assembly, and then select the Decompile source code command. Visual Studio generates a symbol file for the assembly and then embeds the source into the symbol file. In a later step, you can extract the embedded source code.
Extract and view the embedded source code
You can extract source files that are embedded in a symbol file using the Extract Source Code command in the context menu of the Modules window.
The extracted source files are added to the solution as miscellaneous files. The miscellaneous files feature is off by default in Visual Studio. You can enable this feature from the Tools > Options > Environment > Documents > Show Miscellaneous files in Solution Explorer checkbox. Without enabling this feature, you won't be able to open the extracted source code.
Extracted source files appear in the miscellaneous files in Solution Explorer.
Known limitations
Requires break mode
Generating source code using decompilation is only possible when the debugger is in break mode and the application is paused. For example, Visual Studio enters break mode when it hits a breakpoint or an exception. You can easily trigger Visual Studio to break the next time your code runs by using the Break All command ().
Decompilation limitations
Generating source code from the intermediate format (IL) that is used in .NET assemblies has some inherent limitations. As such, the generated source code doesn't look like the original source code. Most of the differences are in places where the information in the original source code isn't needed at runtime. For example, information such as whitespace, comments, and the names of local variables aren't needed at runtime. We recommend that you use the generated source to understand how the program is executing and not as a replacement for the original source code.
Debug optimized or release assemblies
When debugging code that was decompiled from an assembly that was compiled using compiler optimizations, you may come across the following issues:
- Breakpoints may not always bind to the matching sourcing location.
- Stepping may not always step to the correct location.
- Local variables may not have accurate names.
- Some variables may not be available for evaluation.
More details can be found in the GitHub issue: ICSharpCode.Decompiler integration into VS Debugger.
Decompilation reliability
A relatively small percentage of decompilation attempts may result in failure. This is due to a sequence point null-reference error in ILSpy. We have mitigated the failure by catching these issues and gracefully failing the decompilation attempt.
More details can be found in the GitHub issue: ICSharpCode.Decompiler integration into VS Debugger.
Limitations with async code
The results from decompiling modules with async/await code patterns may be incomplete or fail entirely. The ILSpy implementation of async/await and yield state-machines is only partially implemented.
More details can be found in the GitHub issue: PDB Generator Status.
Just My Code
The Just My Code (JMC) settings allows Visual Studio to step over system, framework, library, and other non-user calls. During a debugging session, the Modules window shows which code modules the debugger is treating as My Code (user code).
Decompilation of optimized or release modules produces non-user code. If the debugger breaks in your decompiled non-user code, for example, the No Source window appears. To disable Just My Code, navigate to Tools > Options (or Debug > Options) > Debugging > General, and then deselect Enable Just My Code.
Extracted sources
Source code extracted from an assembly has the following limitations:
- The name and location of the generated files isn't configurable.
- The files are temporary and will be deleted by Visual Studio.
- The files are placed in a single folder and any folder hierarchy that the original sources had isn't used.
- The file name for each file contains a checksum hash of the file.
Generated code is C# only
Decompilation only generates source code files in C#. There is no option to generate files in any other language.
Decompile .NET assemblies to C#
dotPeek is a free-of-charge standalone tool based on ReSharper's bundled decompiler. It can reliably decompile any .NET assembly into equivalent C# or IL code.
The decompiler supports multiple formats including libraries (.dll), executables (.exe), and Windows metadata files (.winmd).
Export decompiled code to Visual Studio projects
As soon as you've decompiled an assembly, you can save it as a Visual Studio project (.csproj). This can potentially save a lot of time if you need to restore lost source code from a legacy assembly.
Download source code and debug third-party code
dotPeek can identify local source code based on PDB files, or fetch source code from source servers such as Microsoft Reference Source Center or SymbolSource.
dotPeek can also perform as a symbol server and supply Visual Studio debugger with the information required to debug assembly code.
dotPeek inherits a lot of features from ReSharper. These include contextual and context-insensitive navigation, usage search, as well as different code structure and hierarchy views.
Find usages of any symbol
Use Find Usages to search for all usages of a symbol, be it a method, property, local variable or a different entity. The Find Results tool window lets you group usages, navigate between them, and open them in the code view area.
Jump to a type, symbol or anything
Whenever you put a caret on a symbol in the code view area, dotPeek offers a plethora of contextual navigation options that are all available via Navigate To drop-down menu.
Navigate to related code
dotPeek indexes all assemblies in your assembly list, as well as all assemblies that they reference, and provides features to quickly jump to specific code. For instance, Go to Everything allows searching for an assembly, namespace, type, member, or a recently opened file.
Long-time users of JetBrains ReSharper will feel at home working with dotPeek as it provides ReSharper-like navigation and search, code insight, and familiar keyboard shortcuts.
dotUltimate: Empowering Your .NET
and Visual Studio Development
dotUltimate is a single license that allows a single developer to use these JetBrains tools:
Freeware Exe Decompiler
dotUltimate license also covers plugins for dotCover and dotTrace in Rider.