Over a million developers have joined DZone.

Have You Met the CLI?

DZone's Guide to

Have You Met the CLI?

Ever wondered what exactly is under the .NET hood? Read here to find out.

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

What enables code written in C#, F#, and VB.NET to run within the same application? And what is .NET anyway?

A Standardized Specification

When I was working on a legacy website developed in VB.NET, I had to implement PayPal Payments Pro. After some searching, I found out that the PayPal team provided several SDKs for different platforms, including .NET, to consume their API. And, guess what? The .NET SDK was developed in C#… but in the .NET world, that’s not a problem. I just referenced the dll (compiled .NET library, similar to the Java equivalent .jar containing .class files) in my project and was good to go. No need to build a client API and re-invent what was already implemented by brilliant developers!

All thanks to the CLI.

The ECMA Common Language Infrastructure (CLI) is an international standard that gives a specification for executable code and the execution environment. The CLI sets standards and rules to allow different languages to be used and run regardless of the operating system, relying on the virtual execution system in which it runs. The elements specified in the standard are: the Common Type System (CTS), the Common Language Specification (CLS), Metadata, Portable file system, Common Intermediate Language (CIL), and the Virtual Execution System (VES).

.NET as a Proprietary Implementation of the Specification

Ok, fair enough, but what does .NET have to do with this? The .NET framework is Microsoft’s implementation of the CLI. Through the platform-specific Common Language Runtime (CLR) .NET provides the VES which among other things, compiles Intermediate Language code (assembly code) to machine-readable code.

The CLR is somewhat equivalent to the Java Virtual Machine as it compiles the Intermediate Language code, previously compiled from C# or F# into machine code. But the CLR does more than that: it provides services to managed code such as exception handling, garbage collection, security… But, what is managed code? Managed code is code written in a language that is compliant with the CLS specification such as C# or .Managed C++, and thus can be compiled to Intermediate Language. (read more)

To sum up, what makes possible for C#, F#, J#, VB.Net, Clojure , and other .NET languages to run together is that they are all compiled to the identical intermediate code. The compilation of code in .NET is done twice: first to compile from the language specific code to the Common Intermediate Language; and, secondly from the CIL to native machine code at runtime.

If you want to explore other implementations of the Common Language Infrastructure specification, you can have a look at the open source Mono platform, or at Microsoft’s open source implementation .NET Core.

This article was first published on the Codurance blog.

Take a look at an Indigo.Design sample application to learn more about how apps are created with design to code software.

.net ,clr ,cli

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}