Decompiler Tools — A friend in need

Prashanth Patali
3 min readNov 25, 2018

--

Do you encounter following situations as part of your job as .NET developer?

  • One of your customers using an old of version of your application reports a bug and you want to quickly check if a specific code is part of the deployed assembly
  • Even after deploying a patch to fix a specific issue, you encounter the bug in UAT/PROD environment and you are unsure if the patch was built with version of the source which has the fix
  • In some environments your application is failing due to dependency issues and you wold like to know what references does the assembly have for dependencies, including the version.
  • Some part of your application interfaces with 32-bit libraries and your app is failing with BadImageFormatException and you would like to know the bitness of your assembly and the process.

Fret Not! You could use a decompiler to help you in all of the above situations.

I will introduce you, briefly, to two such tools.

ILSpy

ILSpy is an open-source .NET assembly decompiler which is actively maintained and has a small (2MB) download size.

Viewing System.Xml in ILSpy

Load your assembly either from a specific folder or from GAC. Expand the loaded assembly to view the various references and namespaces. Listed within each namespace are the classes, enums or structs types. Select any one of these types to see the decompiled code in C# for that type.

Right-click and choose Analyzeto view usage of that type or member. Also select any node in the hierarchy — Assembly, namespace or type — and click File -> Save Code to generate the C# source code for that and all its descendants nodes to a folder.

ILSpy is small, fast and gets the job done.

dotPeek

dotPeek is a free .NET decompiler tool from none other than JetBrains. Its a standalone .exe with size of 57MB. However, compared to ILSpy, it has a good set of additional features and is more polished.

Viewing System.Xml in dotPeek

Like ILSpy, you can load assembly from folder and GAC. But you also browse a folder and all assemblies within it, load an assembly from a running process and from a NuGet package. Navigation within namespace and type is similar to that of ILSpy but source code of each type is displayed in separate tab.

To save the generated code, select the assembly name node and choose File -> Export to Project… menu.

In addition to code generation, references and usage details, dotPeek can visual show the dependencies of the assembly. Select the assembly name node and choose Inspect -> Assembly Dependency Diagram.

Dependency diagram for System.Xml

You may refer to this link for complete list of features.

If size if not an issue and you are impressed by the additional features, then consider dotPeek. I prefer dotPeek on my development machine but do use ILSpy when I have to quickly copy over the small package to a remote server and analyze the assembly on the server.

Note: Refer to my earlier post, Bitness of .NET Assembly, to understand how these tool helps in finding the bitness of assembly.

--

--