How can I view MSIL / CIL generated by C# compiler? Why is it called assembly?

walter picture walter · Jul 24, 2010 · Viewed 60.8k times · Source

I'm new to .NET C# programming. I'm following few books. It is said that instead of compiling it directly to binary code (Native code). High level code is converted into intermediate language (called MSIL aka CIL). But when I compile, I get an exe/Dll file.

  1. Is this MSIL/CIL containted in these exe/dll file?
  2. I want to see that intermediate language code. Just to get feel of its existence. How to view it?
  3. They are calling this exe/dll file an assembly. Are they using this "fancy word" just to differentiate these from the exe/dll files that contain binary code (native code)?

Answer

Johannes Rudolph picture Johannes Rudolph · Jul 24, 2010
  1. Yes it is, more exactly in the .text section of the PE file (portable executable = *.exe or *.dll). More information can be found here.
  2. The best choice is to use ILSpy (Reflector is no longer free). It's a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). The .NET Framework SDK contains ILDasm, which is the official MSIL dissasembler.
  3. Basically yes. An assembly is a file that contains MSIL code and corresponding metadata. This is not restricted to PE files per se, but all current CLR implementations use them.

If I may recommend a good book on that matter too, it's Expert .NET 2.0 IL Assembler by Serge Lidin. He's the guy who designed MSIL.