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).
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:
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!