Click here to monitor SSC

Bart

Software Engineer - Red Gate Software

.NET Reflector Support: How can I set breakpoints in the code I've decompiled when debugging?

Published Wednesday, August 19, 2009 12:47 PM

I see this question come up from time to time in the .NET Reflector mailbox, so I'm going to make a stab at a sensible answer that's more than just a some marketing fluff piece, because there are alternatives, although it's debatable how realistic they are.

You basically have three options:

  1. Create a debug build of the assembly you're interested in using the generated source code.
  2. Use the Deblector add-in from within .NET Reflector.
  3. Wait for .NET Reflector Pro, or at least an early access build of the product-should be available in the next month or two-and use that instead.

If you've been following my previous posts, you'll be aware that it's possible to decompile an entire assembly, and even generate a Visual Studio project for the decompiled source:

http://www.simple-talk.com/community/blogs/bart/archive/2009/07/30/74199.aspx

http://www.simple-talk.com/community/blogs/bart/archive/2009/07/31/74222.aspx

So, at least in theory, you should be able to fire up Visual Studio and build a debug version of the assembly you've decompiled (option 1). There are a couple of reasons this probably won't work, which I'll talk about below, but let's assume for a minute it does work; what you then need to do is substitute any references to that assembly in your project with references to the debug version. Then, when you're debugging, you can set break points in the generated code and debug it, just as you would any other source code.

OK, sounds good, so why is it unlikely to work?

  • .NET Reflector may not be able to decompile everything in the assembly, or may generate some source code that isn't quite correct, or won't recompile. Many of the reasons for this are discussed at http://www.simple-talk.com/community/blogs/bart/archive/2009/07/30/74203.aspx. Thus, you'll get build errors in Visual Studio when you try to recompile the assembly, unless the code in the original assembly is relatively simple and was compiled from an OO/imperative language, such as C# or VB.
  • If the assembly you've decompiled is used by other assemblies that you haven't decompiled, they probably won't work with the debug build you've created, even assuming it recompiles successfully. To get around this you'll need to decompile all of the other assemblies that reference the assembly you're interested in, and then recompile them against the debug build you've created. The chances of this working are minimal.

So, option 1 is probably out.

Option 2 involves using Deblector to debug the assembly from within .NET Reflector itself. You can find Deblector here:

http://www.codeplex.com/deblector

The downside here is that documentation is sketchy and there hasn't been any activity on the project since early 2008, which makes me think it's probably dead.

Option 3, which isn't really an option yet, if I'm completely honest, is to use .NET Reflector Pro. If all goes well, I'd like to see an early access build out there that you can use within the next month or two. As any of you who have used our early access builds before will know, they're generally pretty usable, albeit with bugs in them, but I'd say this is probably your best option in the longer term.

EDIT: .NET Reflector Pro is now in beta. Download instructions are available here: http://www.red-gate.com/messageboard/viewforum.php?f=109.

by Bart Read
Filed Under: , ,

Comments

 

Jason Haley said:

Interesting Finds: August 20, 2009
August 20, 2009 6:40 AM
 

Jason Haley said:

Interesting Finds: August 20, 2009
August 20, 2009 6:45 AM
 

Zsolt Petreny said:

Or you can just debug the code using DILE (without Visual Studio). It might also seem to be a dead project but if I have time then soon it will "resurrected". :-)
August 21, 2009 8:23 AM
You need to sign in to comment on this blog

About Bart Read

Bart has done many things since he started work at Red Gate Software Ltd in August 2004, but nowadays he's (mainly) the product manager for the .NET Developer Tools. He still feels like this is a bit like admitting you were cheering for the Empire whilst watching Star Wars, but for now he's along for the ride. In a previous incarnation he was a project manager leading the .NET Reflector Pro, ANTS Memory Profiler 5, ANTS Performance Profiler 4 & 5, and SQL Prompt 3.0 - 3.6 projects. He still occasionally writes some code and, in the past, has touched the code for most of the Red Gate SQL developer tools... some of them still haven't recovered from the shock. He was born and grew up in Dorset, was educated in Nottingham and London, and likes music and real ale. His photo is extremely misleading.
<August 2009>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. Wesley David... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across and started getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...