views:

104

answers:

6

Hello,

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)?
+3  A: 

In many respects, .NET assemblies are similar to Java bytecode packages.

  1. Yes. They also contain manifests and other data, but the CIL is part of the exe/dll.
  2. Use ILDasm or Reflector - most people would say Reflector, as it is much more powerful. Both will show you what CIL was produced. Wikipedia has a list of all CIL instructions, for a better feel (it is assembly like).
  3. I guess it is meant as an assembly of code. A good way to differentiate it from native.
Oded
+5  A: 
  1. Yes it is in assembly.
  2. You need .NET Reflector or ILDasm.
  3. More details on assembly check HERE.

P.S As you are following some books I will highly recommend you CLR via C#.

Incognito
+1 for CLR via C#, it is really a great book!
NDeveloper
+6  A: 
  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 Reflector. 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.

Johannes Rudolph
Wait! It isn't located in `.text` sextion? If not, what does `.text` contain? and whats up with the `#` I thought sections are named beginning with `.`. So souldn't it be `.strings`
Yeah, you're right walter (slapping my forehad). #strings is an assembly thing inside .text.
Johannes Rudolph
+1  A: 

From my experience the best source of IL-related knowledge is Andrew Troelsen “Pro C# and .NET Platform”. Starting from 3rd edition he has really, really outstanding chapter (approx 50 pages) on how to understand IL and even write your own code and use ILAsm. I’ve employed that information to investigate whether multiple inheritance exists in .NET world. Also you could try to employ some very interesting features in IL (e.g. filtering of exceptions which only exists in VB but not in C#).

I highly recommend to read that chapter.

Eventually, .NET Reflector is an enterprise standard for investigating IL code of assemblies and Richter's book is definitely "must read" stuff. But from other books like mentioned above you could reveal really useful things :)

Yes, each assembly in .NET world holds some IL code (alongsite with manifest) which could be viewed thru Reflector or ILDasm. Even more, Reflector could show you C# and VB optimized code. This means that any person could view the source code of an assembly and that's why in commercial products obfuscators are used.

xenn_33
+3  A: 

I believe that they are called "assemblies" because an assembly is a set of modules, assembled together by a manifest.

multi-file assembly

See Assembly Contents for details.

John Saunders
claws
+1  A: 

One of my favorite ways to see IL for a snippet of C# is to use the free LINQPad tool. After entering some code and choosing "C# statements" at the top (or "C# Program", whichever suits), click the "IL" button under the code entry area, and you will see the generated IL.

Using LINQPad for this is much more convenient than loading up Visual Studio or running the compiler from the command line, then loading up ILDASM and opening the .il file with a text editor.

Mark Rushakoff
Another good tool is the Snippy add-in for Reflector: http://jasonhaley.com/blog/post/2008/11/23/ReflectorSnippy-Addin.aspx
Thomas Levesque