In .NET, when an application is compiled, into a bytecode called MSIL. That MSIL code is stored in an assembly. The assembly is contained in one or more PE (portable executable) files and may end with an EXE or DLL extension.
The assembly contents are:
Byte code — The code in MSIL language.
Security Information — Information about the users / user types, who can access the assembly.
Manifest — Information about the assembly, such as identification, name, version, and so on.
Versioning — The version number of an assembly.
Metadata — Information that describes the types and methods of the assembly.
Types of Assemblies
Private Assemblies: The private assemblies are simple types. An assembly that can be used only within a software application is called as “Private assembly”.
Shared Assemblies: An assembly that can be used by one or more software applications is called as “Shared Assemblies”.
Example:
To get a better idea of a MSIL file and its content, take a look at the following example, which has two console applications. One is written in C# and the other is written in VB.NET.
The following C# code displays the “Hello, World” message in the console window:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorldCS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello, World!”);
Console.ReadLine();
}
}
}
The following VB.NET code displays the “Hello, World” message in the console window:
Module Module1
Sub Main()
Console.WriteLine(“Hello, World!”)
Console.ReadLine()
End Sub
End Module
The Main method of the C# MSIL looks like this:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 19 (0x13)
.maxstack 8
IL_0000: nop
IL_0001: ldstr “Hello, World!”
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: call string [mscorlib]System.Console::ReadLine()
IL_0011: pop
IL_0012: ret
} // end of method Program::Main
The Main method of the VB.NET MSIL looks like this:
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 20 (0x14)
.maxstack 8
IL_0000: nop
IL_0001: ldstr “Hello, World!”
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: call string [mscorlib]System.Console::ReadLine()
IL_0011: pop
IL_0012: nop
IL_0013: ret
} // end of method Module1::Main
Conclusion: The Main method of the VB.NET MSIL looks very similar to that of the C#.NET’s MSIL program.
The important thing to note here is that regardless of the language you use to develop your .NET applications, all .NET applications are compiled to the MSIL bytecode as this example shows.
Note: MSIL can also be called as IL (Intermediate Language) and CIL (Common Intermediate Language).