Search⌘ K
AI Features

Decompiling .NET Assemblies

Explore the process of decompiling .NET assemblies with ILSpy and Visual Studio 2022 to understand how C# code is implemented. Learn to navigate assembly trees, review source code in C# and IL, and use Visual Studio's source link feature. This lesson helps you appreciate best practices in professional code and clarifies why compiled .NET code can be decompiled but not fully protected from it.

One of the best ways to learn how to code for .NET is to see how professionals do it. We could decompile someone else’s assemblies for non-learning purposes, like copying their code for use in our own production library or application, but remember that we are viewing their intellectual property, so please respect that.

Decompiling using the ILSpy extension for Visual Studio 2022

For learning purposes, we can decompile any .NET assembly with a tool like ILSpy:

Step 1: In Visual Studio 2022 for Windows, navigate to “Extensions | Manage Extensions.”

Step 2: In the search box, enter ilspy.

Step 3: For the ILSpy 2022 extension, click “Download.”

Step 4: Click “Close.”

Step 5: Close Visual Studio to allow the extension to be installed.

Step 6: Restart Visual Studio and reopen the solution.

Step 7: In Solution Explorer, right-click the DotNetEverywhere project and select “Open output in ILSpy”.

Step 8: In ILSpy, in the toolbar, ensure that C# is selected in the drop-down list of languages to decompile into.

Step 9: ...