There can be some other reasons, except those listed in the excellent answer by Mehdi.
Some cases from my practice:
- In some really advanced programming, you need to use IL or, in more practical cases,
System.Reflection.Emit
, to emit code on the fly, which is the key to some technologies, such as serialization, and, say, automatic generation of UI based on data or interfaces. Such work is pretty difficult and needs good knowledge of IL. Here is what I do: I create short code samples in C#, disassemble them and see how the compiler generates the IL code, to learn it and write correct Emit code. - In some works published on CodeProject, people developed very interesting technique of using .NET code in unmanaged code, without resorting to ugly COM components. The approach is based on adding special attributes to members to be exported to unmanaged, automatic assembling of the code, disassembling it, modification of it and assembling again. Please see:
loading C# DLL in MFC[^],
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
API's in .Net: Managed or UnManaged Code[^].
I would add that first case is just one of the cases where using disassember is useful for learning. IL documentation is not really good, the only real source is the ECMA standard on CLR, and Emit documentation is too brief.
Those are advanced rarely used techniques, but disassembly is also used rarely.
Finally, I would like to recommend wonderful open-source product which can be used for disassembly and translation between .NET languages:
http://www.ilspy.net[
^],
see also
http://en.wikipedia.org/wiki/.NET_Reflector[
^], where ILSpy is mentioned, as well as some other products.
—SA