How do I decompile a .NET EXE into readable C# source code?

C#.NetReverse EngineeringDecompiling

C# Problem Overview


I wrote a C# application for a client a couple of years ago, but I no longer have the source code. All I have is the EXE that I deployed on the client's PC. Is there a way I can generate C# source code from the EXE?

C# Solutions


Solution 1 - C#

Reflector and its add-in FileDisassembler.

Reflector will allow to see the source code. FileDisassembler will allow you to convert it into a VS solution.

Solution 2 - C#

When Red Gate said there would no longer be a free version of .Net Reflector, I started using ILSpy and Telerik's JustDecompile. I have found ILSpy to decompile more accurately than JustDecompile (which is still in Beta). Red Gate has changed their decision and still have a free version of .Net Reflector, but now I like ILSpy.

From the ILSpy website (https://github.com/icsharpcode/ILSpy/):

ILSpy is the open-source .NET assembly browser and decompiler.

ILSpy Features

  • Assembly browsing
  • IL Disassembly
  • Decompilation to C#
  • Supports lambdas and 'yield return'
  • Shows XML documentation
  • Saving of resources
  • Search for types/methods/properties (substring)
  • Hyperlink-based type/method/property navigation
  • Base/Derived types navigation
  • Navigation history
  • BAML to XAML decompiler
  • Save Assembly as C# Project
  • Find usage of field/method
  • Extensible via plugins (MEF)

Update:

April 15, 2012, ILSpy 2.0 was released. New features compared with version 1.0:

  • Assembly Lists
  • Support for decompiling Expression trees
  • Support for lifted operatores on nullables
  • Decompile to Visual Basic
  • Search for multiple strings separated by space (searching for "Assembly manager" in ILSpy.exe would find AssemblyListManager)
  • Clicking on a local variable will highlight all other occurrences of that variable
  • Ctrl+F can be used to search within the decompiled code view

Update:

  • ILSpy 2.1 supports async/await decompilation

Solution 3 - C#

Reflector is no longer free in general, but they do offer it for free to open source developers: http://reflectorblog.red-gate.com/2013/07/open-source/

But a few companies like DevExtras and JetBrains have created free alternatives:

http://www.devextras.com/decompiler/">DevExtras CodeReflect

JetBrains DotPeek

Solution 4 - C#

Reflector and the File Disassembler add-in from Denis Bauer. It actually produces source projects from assemblies, where Reflector on its own only displays the disassembled source.

ADDED: My latest favourite is JetBrains' dotPeek.

Solution 5 - C#

Telerik JustDecompile is free and has a feature to create projects from .NET assemblies.

Solution 6 - C#

I'm surprised no one has mentioned Microsoft's ildasm. It may not be as pretty as ILSpy or Reflector, but it comes with Visual Studio so many developers already have it.

To run it (assuming VS 2013, should be similar for other versions):

  1. Select Start > All Programs > Visual Studio 2013 > Visual Studio Tools.
  2. Double-click on Developer Command Prompt for VS2013.
  3. Run "ildasm" from the resulting command prompt.
  4. In the tool, select File > Open and open your executable or DLL.

Now you can navigate the DLL structure. Double-click on class members to see the IL. Use File > Dump to export IL to a file.

Solution 7 - C#

You want reflector.

Solution 8 - C#

I'm surprised no one has mentioned dnSpy. dnSpy is a debugger and .NET assembly editor. You can use it to edit and debug assemblies even if you don't have any source code available.

Main features:

  • Debug .NET and Unity assemblies
  • Edit .NET and Unity assemblies
  • Light and dark themes

It is open source and one of most widely used reverse engineering tool for dot net.

Solution 9 - C#

There are various .NET / C# Decompilers available nowadays (2022):

  • ILSpy for everyone [free OSS C# IL multi-platforms]
  • dotPeek for convenient decompilation [free C# IL]
  • dnSpy for gurus, security and hackers [free OSS C# VB IL]
  • JustDecompile for everyone [free OSS C# VB IL] (continued as CodemerxDecompile)
  • IldAsm for nostalgia [free IL]
  • .NET Reflector for history [commercial unsupported C# VB IL MC++]

My preference goes to ILSpy because it is free, OSS, very fast (compared to others), so well maintained it is even used by Visual Studio and decompiled code is accurate. This blog post In the Jungle of .NET Decompilers explains in details all these .NET decompilers.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMusiGenesisView Question on Stackoverflow
Solution 1 - C#GEOCHETView Answer on Stackoverflow
Solution 2 - C#DanielView Answer on Stackoverflow
Solution 3 - C#arcView Answer on Stackoverflow
Solution 4 - C#ProfKView Answer on Stackoverflow
Solution 5 - C#kodefuguruView Answer on Stackoverflow
Solution 6 - C#yoyoView Answer on Stackoverflow
Solution 7 - C#Luke HalliwellView Answer on Stackoverflow
Solution 8 - C#NoteworthyView Answer on Stackoverflow
Solution 9 - C#Patrick from NDepend teamView Answer on Stackoverflow