Common Language Integration in .Net Framework



Introduction:

CLI (Common Language Integration) is an important concept in .Net Framework. As you, .Net supports multiple languages; more than 100 in Visual Studio 2010. Now you want to add two DLLs (dynamic Link Libraries) to your project but one DLL is in C# language and other is in VB Language and when we use both languages together we are getting the same output without any error. So this is the concept of CLI. Now we see how does it happen?

Summary:

Open two different Class Libraries such as ClassLibrary1 and ClassLibrary2, one should be in C# and other should be in any language Like VB. OK.

Open ClassLibrary For C#:

fig1.gif

Open ClassLibrary For VB:

fig2.gif

After that just write a code in both languages like in C#

namespace ClassLibrary2
{
    public class Class1
    {
        public int a;
    }
}

In VB

Public Class Class1
    Public a As Integer
End Class

(Remember we are working in ClassLibrary). And now just compile both projects and we will get two different DLLs; one in C# and one in VB.

Now open command prompt of Visual Studio

fig3.gif

And write the command "ILDASM" (Intermediate Language Disassembler) over there and press enter; do it 2 times.

fig4.gif

We will get two same ILDASM windows Like:

fig5.gif

In one just add C# DLL and in other add VB's DLL.

For add (file->open->follow the path for DLL),

fig6.gif

And now you will see that both languages code are the same at that position like this:

fig7.gif

Now we can see that on this position code for variable "a" is same in both windows. This position is known as MSIL (Microsoft Intermediate Language).

So how does it happen, when we use more than one language on .Net platform then you will see that .Net does not understand the languages you use over there, that only understand the MSIL code. So whenever we use any language the language's compiler converts that code to MSIL. That is why .Net only converts the MSIL code while code is written in any language, that does not matter. Then this is the reason, where we can say .Net support CLI.

By,
Yogendra Kumar
 

erver'>