Sonu
Sonu

Reputation: 458

Confused about MSIL

I read the c# program compilation takes two steps.

First it generates MSIL and then it produces the machine code. So I am curious to see the files generated by first phase of compilation (MSIL).

I have been thinking the DLL file is the file which contains the MSIL code, but I think I am wrong.

Upvotes: 1

Views: 2537

Answers (2)

Amir Popovich
Amir Popovich

Reputation: 29836

.net has multiple languages (C#, VB.net etc.).

When you compile a C# project library, it outputs a dll that contains IL code.

C# compiles to IL as VB.net compiles to IL and therefore you can "mix up" code between to two languages.

This IL is compiled to machine code using the JIT compiler in runtime (read about the CLR).

You can see IL code by using a reflector and reflecting a dll.

Read more here.

Upvotes: 2

Patrick Hofman
Patrick Hofman

Reputation: 156978

You are right. .NET DLL's and EXE's (called assemblies in .NET) are the ones that contain MSIL. DLL's can have another format than the .NET ones, so that's why the .NET assemblies have a header that makes them recognizable as such. You can use corflags.exe to check if an DLL/EXE is a .NET DLL/EXE.

The IL code in the assembly is interpreted by the CLR (Common Language Runtime), which translates it to machine code. You can't see that step actually since it is done by the JIT'ter at runtime (or you should pre-compile the assemblies using ngen.exe and read the generated files).

Upvotes: 5

Related Questions