.NET Reflector Saved their Bacon: Chris Kapilla’s Story

.NET Reflector is not just a handy adjunct to Visual Studio for developers to browse their assemblies and understand classes and methods; Sometimes it can have a vital role. Many developers have told us that, occasionally, it had 'saved their bacon'. We were intrigued and decided to find out more by offering prizes and cash for ".NET Reflector Saved My Bacon" stories.

Late last month, Chris Massey, a Simple-Talk writer and editor, put out a call for anyone with stories about how .NET Reflector saved their day. Simple-Talk received several responses. They tend to reflect the many stories that one comes across in blogs: Typically, the latest source of a VB or C# application gets lost, and .NET Reflector is used for its powers of decompiling the IL code of the assembly into the C# or VB code that could produce that IL. 

One story that we heard from a developer is typical of the disasters that can befall a software project. She is a software developer with 12 years of experience, the last eight almost exclusively using Microsoft technologies.  Most of her projects are web applications.  She didn’t want her name published because she was concerned that “it makes me sound like an idiot.”  The story she told us evoked only sympathy. You’d be surprised how many professional developers have had the experience when working long hours under pressure. Mistakes happen!

The episode occurred when she attempted to convert a Visual Studio 2003 project to VS 2005.  The conversion failed, mangling the source completely. She thought she had up-to-date backups, but didn’t.  And, she trusted the conversion wizard to back up the original files – it didn’t.  She was suddenly left without the source code, and very much wished she wasn’t!

After the usual waves of panic had subsided, she discovered .NET Reflector, and she used .NET Reflector to reverse-engineer the original ..DLL, and was able to recreate the source file, losing only the comments. She used Denis Bauer’s .FileDisassembler add-in  to  dump the decompiler output to The VB.NET source.

Bacon saved.  And except for a scare that she’ll never forget, no one was the wiser, except her.

The Kapilla story

Chris Kapilla’s story is from two years’ ago, and he remembers it as if it was yesterday.  Kapilla has been a developer for more than 20 years and an independent consultant since 1995.  He feels he was born again with the advent of the .NET Framework, and has been using it to develop applications for the desktop, server applets and websites in C# since 2001.

Here’s the episode in Chris’ words, with only minor edits. 

“In February 2007, I was looking for some additional consulting work.  I contacted a local organization (which shall remain nameless for soon-to-be-obvious reasons) to see if they had anything that I could help them with.  In 1999-2000 I had written a Microsoft Word VBA document management system for them that they retail to members of their organization. Upon completion, I had moved on to other things and lost contact with them.”

Who moved my…application?

‘I wasn’t really
 expecting much’

“After talking with them I found out that they had utilized the services of another company to move their application to a Word COM Add-in, but the developer had dropped off the face of the earth.  Despite the company’s best efforts, they were not able to contact him.  Amazingly, they did not have any source code for their product, and it was showing serious signs of needing some updates.  Of course, they were completely unable to make any product changes.”

“I didn’t say anything in my initial meeting with the client, but I thought it might be possible to recover the source code for the product if it hadn’t been obfuscated.”

“I had heard that .NET Reflector was good at retrieving source code from a compiled assembly and thought it was worth a try, but I wasn’t really expecting much.”

Reflector to the rescue

“After opening the component .DLLs of the application and browsing to the method signatures in Reflector, I was delighted to see the beautifully formatted C# source code produced for each method.  Since there were more than a hundred methods in this one class, however, the process of extracting each method’s source code soon started to get tedious. “


“It was then that I discovered the Expand Methods links at the bottom of each class definition:…”


“Clicking on this presented me with a complete class definition in one fell swoop:”


“From this point, it was clear sailing to create a complete set of source code for the entire project. Of course getting a clean compile out of all this was a non-trivial task – in large part because of ambiguous references between Windows.Forms types and Office.Core types. Reflector’s hyperlinks would tell me which type the reference was in each case, but the code needed to be tweaked in a number of places to get everything squared away.”

“Still, extracting the source for all the ..DLL and .exe and making the adjustments necessary for a clean compile took only 14 hours.” 

“Once I recovered the source, there was a lot of debugging to do.  The biggest stumbling block was that COM add-ins make use of an unmanaged “shim” .DLL moderates between the unmanaged Word application and the managed .DLL.”

“Since the source code for the shim was not available, the only option was to create a new one from scratch.  Very fortunately, Microsoft provides a COM Shim Wizard that automates the creation of a C++ ATL project.  From that point it was only a matter of getting all the registry settings correct and I had a running application.”

“The final part of the project was refactoring the original code into more manageable chunks, splitting out new classes as appropriate, and re-designing a number of the methods.  With this all completed, we were finally back to square one and could begin the work of fixing some bugs and adding some new enhancements, such as a new version of the product for Word 2007:”


Attaining god status 

“I was flabbergasted by what a complete job Reflector did of restoring the C# source code.  I thought I would have to do it in small bits and pieces but Reflector created beautifully formatted code that only required a minimum of tweaks over a few days in order to turn it into a polished set of source code files with more than 20,000 lines of code with five different modules.  I immediately attained god status with my client, although I did give the credit to Reflector.”

.NET Reflector is free, and can be downloaded here: An up-to-date listing, and the location of the latest version,  of add-ins is always kept at CodeProject:. The Add-Ins are reviewed here. As simple guide to .NET Reflector is .NET Reflector: Soup to Nuts