Skip to main content

Keene Systems, Inc.

Lost Your .NET Source Code? How to Recover It With a .NET Decompiler

If your ASP.NET programmer has disappeared and the source code is missing, the application can usually still be modified and maintained. A .NET decompiler reads the compiled DLL and EXE files that are running today and turns them back into readable C#. The page files and the database supply most of the rest. Keene Systems recovers the code, gets it building again and takes over the application. The decompiler does only part of the job: the recovered code still needs experienced developers to make it build, run and stay maintainable.

A running application is not the same as having the source code

Many business owners believe they have the source code to their application when they do not. The reasoning is natural: the application is right there on the company’s server, and it has worked for years, so the code must be on that server somewhere.

It usually is not. What runs on the server is the compiled program, the finished product. The source code, the text the programmer wrote and the only form in which the program can be changed, most likely never left the programmer’s own laptop. If that programmer has moved on and cannot be reached, the source code has gone with them.

This comes up often in our work, and it is never a pleasant thing to explain. Seeing the application run does not mean you own its source code, and without the source code nobody can modify or maintain the program.

There is a way back. The source code can be rebuilt from the compiled program. It is not a simple task. A decompiler gets you part of the way, and a good deal of manual work remains before the result builds, runs and can be maintained. It takes a team with experience in ASP.NET and in turning decompiled applications back into working source code. The rest of this page explains how it is done.

Developer concentrating on code at his computer in an office

Signs you are in this situation

  • The person who wrote the application no longer answers calls or email.
  • You asked for the source code and were sent nothing, or something that will not build.
  • The only copy of the program is the one running on the web server or installed on the PCs.
  • The source you do have is older than the version that is running.
  • Nobody knows the passwords to the hosting account or the code repository.
  • A change you need is urgent and there is no one to make it.

First, do not touch the server

The copy of the application that is running today is now the most valuable thing you have. Before anyone tries to fix anything:

  • Take a full backup of the application folder. Every file, including the bin folder and the configuration files. For a desktop program, copy the whole installation folder.
  • Take a full backup of the database. In SQL Server, that includes the stored procedures, views and functions, which are part of the program.
  • Write down every login you know of. The server, the hosting account, the domain registrar, the database, the email service the application sends through.
  • Change the passwords the developer knew, once you are sure you hold working replacements.
  • Do not let anyone “tidy up” the server. Old-looking folders are often exactly where the source turns up.

Why .NET source code is usually recoverable

This is the part most business owners do not know, and it is good news. When C# or VB.NET is compiled, it is not turned into raw machine instructions. It becomes an intermediate language, stored in a DLL or EXE file together with a detailed description of every class, method and property in the program. A decompiler reads that file and writes the C# back out.

That makes .NET very different from older software, where losing the source really did mean starting again. In a typical ASP.NET application you will find:

  • Compiled files that can be decompiled. The .dll files in the bin folder hold the program’s logic.
  • Page files that are often plain text. In a Web Forms application the .aspx and .ascx files usually sit on the server as the developer wrote them. So do the .cshtml views of older MVC applications.
  • Sometimes the source itself. Older “Web Site” projects copy the code files to the server. If you see .cs or .vb files there, you already have the source.
  • A fully readable database. Tables, relationships, stored procedures and triggers can all be scripted out of SQL Server. In many business applications a large share of the rules live there.
  • Configuration files. Connection strings, service addresses and settings show what the application talks to.

How decompiling a .NET DLL or EXE works

Decompiling is not hacking and it is not guesswork. It is a mechanical translation, and for .NET it is reliable. The process runs like this:

  1. Collect the compiled files. For a web application they are in the bin folder. For a desktop program they are the .exe and the .dll files beside it.
  2. Separate your code from everyone else’s. Most of the files in that folder are third-party libraries: reporting tools, grid controls, PDF components. Those are not decompiled. They are identified by name and version and obtained again from their publishers.
  3. Open your own assemblies in a decompiler. Within seconds the tool shows a tree of namespaces, classes and methods, with readable C# for each one.
  4. Export the code as a project. The better tools write out a complete project with one file per class, instead of making you copy code a screen at a time.
  5. Rebuild the solution around it. Project references, configuration, page files, images, scripts and database connections are put back so the whole thing opens in Visual Studio.
  6. Make it compile. Exported code rarely builds on the first attempt. There are usually some dozens of small errors to correct by hand where the tool could not be sure what the developer wrote.
  7. Prove it is the same program. The rebuilt application is run beside the original and compared, screen by screen and report by report.

The first four steps take hours. The last three are where the skill and most of the time go.

.NET decompiler tools

Several mature decompilers exist, and most are free. These are the ones in common use:

  • ILSpy. Free and open source, and the most widely used. It can save a whole assembly as a C# project. Its decompiling engine is the one Visual Studio itself uses.
  • dnSpy. A decompiler combined with a debugger and an editor. It can step through a running program that has no source, and can change a compiled file directly. The original project is no longer maintained, and a community continuation called dnSpyEx carries it on.
  • dotPeek. A free decompiler from JetBrains, the company behind ReSharper. It exports to a Visual Studio project and is comfortable for anyone who knows JetBrains tools.
  • JustDecompile. For years a free decompiler from Telerik. It has been retired, although plenty of developers still have a copy installed.
  • .NET Reflector. The original .NET decompiler, now a commercial product from Redgate, with Visual Studio integration.
  • Visual Studio. Recent versions can show decompiled C# for a library while you are debugging, which is handy for a quick look but not for recovering a whole application.

For a recovery job the choice of tool matters less than people expect. Their output is similar, and we often run a difficult class through two of them and keep the cleaner result. The tool gives you text. Turning that text back into a maintainable application is the real work.

What a decompiler gives back, and what it cannot

Comes back intact:

  • Namespaces, classes, methods, properties and their names.
  • The logic inside every method: the calculations, conditions and loops.
  • Text built into the program, such as messages and SQL statements.
  • Embedded resources: images, report layouts and other files packed inside the assembly.

Does not come back:

  • Comments. The compiler discards them.
  • Names of local variables, unless the .pdb files were deployed alongside the DLLs. Without them you get names like text2 and num3.
  • The original layout. How the code was spaced, ordered and split across files.
  • The project structure. Solution files, build settings and the list of packages have to be reconstructed.

Comes back, but needs attention:

  • VB.NET programs. C# and VB.NET compile to the same intermediate language, so a VB.NET application is usually decompiled into C#. It works, but it reads differently from what the developer wrote.
  • Precompiled web sites. If the site was published as “not updatable”, the .aspx files on the server are empty placeholders and the page layouts are inside the DLLs. They are recoverable, as code that has to be turned back into page markup.
  • ASP.NET Core views. Razor views are normally compiled into the application, so they are recovered the same way.
  • Obfuscated code. Some developers run a tool that scrambles names before release. The logic is still there, with meaningless names. This is uncommon in custom business software.

Can any EXE be turned back into source code?

No, and it is worth knowing which kind you have before you plan anything.

  • .NET programs (C#, VB.NET, ASP.NET, WinForms, WPF): yes, as described above.
  • Programs compiled to native machine code (C++, Delphi, and .NET applications published with native compilation): no. Tools exist that produce low-level listings, but nothing a business application can be maintained from.
  • Visual Basic 6: partly. Forms and their layout can be recovered. The code behind them generally cannot. See modernizing a VB6 application.
  • Microsoft Access: an .accdb or .mdb file holds its own source. A compiled .accde or .mde file does not.

The quick test is to open the file in one of the decompilers above. If it shows a tree of classes, it is .NET and the code is recoverable. If it reports that the file is not a .NET assembly, it is not.

From decompiled code to a system you can change

Decompiled code is a starting point, not a finished product. Our ASP.NET developers turn it into a proper project again. Once the rebuilt application matches the live one, we put the code under source control in an account your company owns, give the generic names meaningful ones in the areas that will be worked on, and write down how the system fits together, since nobody else will have.

Then we make the first real change, test it and deploy it. That deployment is the proof that the system is back under control. From that point it is an ordinary application with an ordinary support team. See ASP.NET application support and takeover for how that continues, or ask for a code audit first if you want a written opinion on what you have before deciding.

When the developer has the code and will not hand it over

Sometimes the developer has not vanished. They are holding the code back over a dispute, or simply not answering. Whether you are entitled to it depends on what your agreement with them says, and that is a question for your attorney, not for a software firm. The same applies to decompiling: it is a normal way to recover software that was written for your company, and if ownership is in dispute you should take advice first.

What we can tell you is that you are rarely as stuck as it feels. If the application is running on a server you control, the recovery described above does not depend on the developer’s cooperation. We have written more about that situation in when a developer is holding your code hostage.

It is also why our own contract states that the client owns the intellectual property of everything we produce for them, source code included, and why the code lives in a repository the client can reach.

When rebuilding is the better answer

Occasionally recovery is possible but not sensible: the application is very old, small, or built on something that is no longer supported. In that case the running system becomes the specification for a replacement. Every screen, report and rule is visible, and the data comes across intact. Our general guide to lost source code covers that route, and Web Forms and .NET Framework migration covers moving an old ASP.NET system forward.

How Keene Systems recovers a .NET application

  1. We talk first. You tell us what the application does and what you still have access to.
  2. We secure a copy. Full backups of the application files and the database are taken before anything else.
  3. We recover the source. Your assemblies are decompiled, page files and database objects are collected, and the project is rebuilt.
  4. We prove it matches. The rebuilt application is compared with the live one until they behave the same.
  5. We hand you the keys. The code goes into a repository your company owns, with a written description of the system.
  6. We carry on. Fixes and new features follow from the same developers, with no minimums or monthly commitments.

The next step is a short, no-pressure conversation. Schedule an ASP.NET project exploration call or use the form on this page.

Frequently asked questions

My ASP.NET programmer disappeared with the source code. Can the application still be modified and maintained?

Usually, yes. The compiled .dll files of an ASP.NET application can be decompiled back into readable C#, and the page files and database logic are normally still readable on the server. From those a working project is rebuilt, and the application can then be changed and maintained like any other.

Can you decompile a DLL back to source code?

For a .NET DLL, yes in most cases. .NET compiles to an intermediate language that a decompiler such as ILSpy, dnSpy or dotPeek converts back to C#. Class names, method names and logic are recovered. Comments are not, and local variable names are lost unless the .pdb files are available.

Can you convert an EXE to source code?

If the EXE is a .NET program, yes: it decompiles the same way a DLL does. If it was compiled to native machine code, as C++ and Delphi programs are, it cannot be turned back into maintainable source code.

What is the best .NET decompiler?

ILSpy is the most widely used and is free and open source. dnSpy adds a debugger, dotPeek comes from JetBrains, and .NET Reflector is a commercial product from Redgate. Their output is similar. For recovering a whole application, the skill of rebuilding the project matters more than the choice of tool.

How close is decompiled code to the original?

Functionally it is the same program. It reads differently from what the developer typed: comments are gone, some names are generic and the project structure has to be rebuilt. Part of our work is cleaning it up and documenting it so it can be maintained.

Can obfuscated .NET code be decompiled?

Yes, but the result is harder to work with. Obfuscation replaces meaningful names with meaningless ones and can tangle the flow of the code. The logic remains, and tools exist that undo part of the scrambling. It is uncommon in custom business applications.

Is decompiling our own application legal?

Recovering code for software that was written for your company and that you have the rights to is a normal recovery practice. If ownership is disputed, check your agreement with the developer and ask your attorney before proceeding.

What do you need from us to start?

A copy of the application files and a backup of the database. Any old backups, laptops or email attachments from the developer are worth collecting too, because the original source sometimes turns up there.

How do we stop this happening again?

Hold the source code in a repository your company owns, keep the hosting and domain accounts in the company’s name, and work with a team instead of a single individual. Our contract states that the client owns everything we produce for them.

Schedule a Project Exploration Call

This free session is your fastest path to improved business productivity.