Jun 162014
 

If you work with 3rd party .NET libraries, you may find yourself in a situation where you would really, really like to see what is going on “beneath the hood” of that black box, 3rd party assembly you are using.  I have encountered cases where the API documentation wasn’t really clear as to what a method would do with a particular parameter.  I have also had cases where the 3rd party library failed on a call and the cause wasn’t readily discoverable.  For these cases, I have called on a very cool tool, Lutz Roeder’s .NET Reflector.  Unfortunately, that tool has now become a commercial, pay-to-use product of Red Gate Software.  There are several nice additions Red Gate has made to the tool, but for simple decompilation, I recommend the use of the open source, ILSpy tool.

ILSpy is a free, no-frills, .NET decompiler that uses reflection to IL to rebuild code back into C# syntax.  It is a very useful tool and can help with the problems I mentioned before where you really need to see inside assemblies where you don’t have access to the source code.  You can see from this example that I used ILSpy to look into the TryOpen method of the vdDocument class from VectorDraw, a 3rd party control for CAD rendering.  I wondered what was going on with file formats that are not native to VectorDraw (i.e. *.vdml and *.vdcl).

ILSpy Showing the vdDocument.TryOpen Method

ILSpy Showing the vdDocument.Open Method

I drilled into the vdDocument.Open method simply by clicking on the method in the deconstructed code.  That led me to the vdDocument.Open method and the ILSpy seamlessly displayed the code for the method:

ILSpy Showing the vdDocument.TryOpen Method

ILSpy Showing the vdDocument.TryOpen Method

From here, ILSpy shows me the code that it has reconstructed.  I can clearly see the branching around the file types and I can continue to drill down through this code.  I can use this to determine intent for the method or I can use this to see how parameters are used in their code.  This definitely comes in handy when there is some confusion around the use of a particular method.

I highly recommend ILSpy for all your .NET decompilation needs.  It is fast, detailed, and best of all it is free!

  2 Responses to “ILSpy – Debugging 3rd Party .NET Libraries”

  1. I have no idea how they compare in terms of functionality, but another free alternative to Redgate’s Reflector is JustDecompile from Telerik. Also, ReSharper (not free but widely used) has decompilation capabilities coupled directly to it Go To Implementation command.

    • Thanks for the other alternatives, Malcolm. I’m glad there are several options to choose from, just in case someone decides to take another one of these tools commercial!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>