295

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?

2
  • 3
    Ok. Look here ... Teleriks JustDecompile actually decompiled the DLL's that Red Gates Reflector completely screwed up ... there were numerous issues with Reflector ... JustDecompile ... flawless so far ... Jul 3, 2015 at 3:48
  • 2
    I have been using JustDecompile for quite a long time and it is really good at decompiling and package the source files as a ready to compile csproject. It is really active in development and there seems to be no open issues in their repo github.com/telerik/JustDecompileEngine May 29, 2016 at 15:40

10 Answers 10

211

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.

5
  • 4
    My copy of Reflector has an "Export..." option and I have no plug-ins installed. It creates a VS project with all the source code and resources. So why is everyone suggesting FileDisassembler? It is better?
    – Lucas
    Oct 7, 2008 at 22:10
  • Lucas: Out of the box, I have not seen reflector able to do this. FileDisassembler has always been the only way. This may have changed in recent history though I guess. I will check it out.
    – GEOCHET
    Oct 8, 2008 at 11:49
  • LIFE SAVER! dumb ass TFS deleted my project. Although I did tell TFS to delete itself but didnt expect it to remove the project from the local file system. thanks all the same. x
    – Christo
    May 28, 2013 at 5:32
  • Where is FileDisassembler ? :/ Nov 3, 2015 at 6:11
  • It work for .Net framework only. any tool which work for .Net core 3.0 exe ? Oct 12, 2019 at 5:09
168

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
5
  • 1
    I'm using 2.2 and it supports decompiling to IL, VB.NET, and C#. I found this very useful.
    – VoteCoffee
    Oct 30, 2014 at 14:45
  • 1
    It seems Telerik is interested in collecting questionable information from the computer running on it and ILSpy cannot be compiled from sources. Also ILSpy binary mixes up variable names and puts some strange characters in the source code.
    – AaA
    Apr 27, 2016 at 3:00
  • 1
    Note that ILSpy includes a Visual Studio add-in. For ILSpy 2.4 I added the ability to navigate from your Visual Studio source code direct to the decompiled output. Unfortunately there were some late-breaking fixes that are now merged to the ILSpy mainline but did not make the 2.4 release.
    – yoyo
    Jul 20, 2016 at 18:01
  • Brilliant! There's a software company that charge people £100 a time for them to use a "special" tool on your sever in order to fix issues. Managed to get a copy of the tool they used while connected, and then managed to use ILSpy very easily to get the tool unlocking password. No more ripping off customers!
    – HippoDuck
    Jan 19, 2017 at 13:39
  • ILSpy is the best one
    – Pritam
    Oct 3, 2019 at 5:40
70

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:

DevExtras CodeReflect

JetBrains DotPeek

6
  • 5
    Reflector is like 35$. Breaking the bank I know, but its worth 10x that.
    – StingyJack
    Oct 5, 2011 at 16:55
  • 7
    It's worth adding Telerik JustDecompile to the list of free .NET assembly decompilers, too. telerik.com/justdecompile
    – Todd
    Oct 13, 2011 at 21:12
  • 6
    @StingyJack: Great, looks like they heard you! It's now actually 10 the price at $368 if you want the VS2012 disassembler. :/ Feb 9, 2013 at 20:13
  • 2
    I dont hold it against them for making money, but ILSpy (mentioned) in @Daniel's answer is what I am using now.
    – StingyJack
    Feb 11, 2013 at 14:29
  • 3
    It now costs $100 for the standard version and $200 for the version that integrates with Visual Studios. That's a heck of an inflation rate. Although they do offer stuff for free to open source developers: reflectorblog.red-gate.com/2013/07/open-source
    – VoteCoffee
    Oct 30, 2014 at 14:57
39

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.

2
  • I like that dotPeek allows working with an entire folder easily, but as of today they only decompile to c#. Most other decompilers also do vb and IL. It also only supports up to Net 4.5 whereas Telerik supports 4.5.1
    – VoteCoffee
    Oct 30, 2014 at 15:04
  • so dotPeek is totally free or they have restrictions for paid version?. i couldnt see any information on jetbrains website regarding it.
    – Emil
    Jan 5, 2019 at 15:33
30

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

2
  • Telerik offers the ability to decompile to VB.NET, IL, or C#.NET which I found useful. It also auto-selects the framework and has a plug-in available for deobfuscicating. Also, it support .NET 4.5.1. Seems pretty good.
    – VoteCoffee
    Oct 30, 2014 at 14:54
  • 1
    I tried all the solutions here in this post and JustDecompile was the only one that works perfectly for me. Jan 17, 2017 at 14:41
29

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.

4
  • I find IL DASM to be a bit barbaric. It shows the tree , but when right clicking does nothing I find that insane. Plus the Dump of the export to file is basically garbage. Look at it, how it that even remotely helpful? Nov 3, 2015 at 6:10
  • 6
    I never claimed ildasm was the best option out there, only that it's available and it works. ¯_(ツ)_/¯
    – yoyo
    Nov 4, 2015 at 0:41
  • Nope, 'fraid not.
    – yoyo
    Jan 11, 2017 at 1:34
  • 1
    I was really surprised that dotPeek would not let me search the whole Assembly for a string I knew was in there. ildasm may not be pretty but at least it has a dump option that helped me locate the class that contained the string I was looking for. Nov 19, 2018 at 19:11
15

You want reflector.

12

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.

1
  • not sure why I got downvoted, I am simply listing a tool which is used by most dotnet reverse engineers today. And IMHO, it does answers the question the question which is getting the source code of an app compiled in C#.
    – Noteworthy
    Jan 11, 2021 at 12:13
8

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.

1

CodemerxDecompile is the continuation of JustDecompile. It uses the same engine but updated for the latest versions of the .NET framework. And it is truly multi-platform running on Windows, Mac and Linux employing AvaloniaUI.

Sadly, JustDecompile has been abandoned for years now. There has been no release with new features since 2017. Lately the open source decompilation engine was removed from gitHub too.

The original team revived it with CodemerxDecompile stepping on the last public version of the open source decompilation engine and building on top of it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.