Gold Award WinnerGold Award Winner

.NET through a bird’s eye view

Microsoft began working on the first .NET framework back in the late 90s before shipping it for the very first time in the year 2002 as a single framework. Since then, it has been a continuous journey of revolutions and revelations into the IT industry worldwide.

Background

.NET today, is a set of verticals, which has received wide support from programmers and developers for its stable and unswerving programming model, security and debugging which made it a popular choice and preference among them.

After its original release in 2002, .NET Compact Framework followed shortly which was designed as a subset of the full framework specifically for Windows Mobile. This framework consisted of a separate code base from the .NET framework having its own runtime, framework and an application model. This set of verticals has since then been into replication repetitively for all the subsets that followed – Silverlight, Windows Phone, Windows Store etc. Because .NET is a set of platforms of which each is maintained separately, this has resulted in fragmentation due to a lack of systematic approach.

Fragmentation is not a problem at all if the target is a single platform. The problem occurs when there is not one but multiple platforms to be targeted and the APIs optimized for one platform cannot be targeted for the others. Let’s have a look at the .NET framework through a simple diagram:



From the above diagram, let’s extract two vertical, let’s say the desktop and the store ones and try to implement a small piece of code on both of them using the same set of libraries:

The problem of the drawing problem

Let’s assume that we want to create a program for drawing a circle. The .NET Framework class library for this purpose is the System.Drawing namespace. Open your Visual Studio coding environment, start a desktop application and write the code for drawing a circle using this namespace. Done? Now let’s move on to the same program for Windows Store. Now using the same namespace write a similar code for drawing a circle there. What’s that? System.Drawing does not exist? How are you going to draw a circle now?

Windows.Graphics.Imaging namespace in the answer to that question and fragmentation in all subsets of the .NET Framework. So according to the example given above, one cannot simply use the same dll for drawing in the native .NET Framework for all the platforms. This means that you need to possibly start from scratch for every different platform you will be targeting other than the original one you wrote the code in for.

Windows 8 Introduces the Concept of Portable Class Libraries

With the release of Windows 8, the concept of code sharing across the platforms took birth. Before that there were no portable class libraries or shared projects which meant going through the uphill task of recreating everything from scratch for every other platform. It was truly a nightmare for a developer who had to repeat the cycle of endless nights of coding every time they wanted to target a new platform. Thus, Windows 8 introduced .Net for metro-style apps through the concept of better subsetting via contracts.

Contracts are assemblies that you simply compile against and are designed around proper factoring. (Refactoring is the process of altering an application’s source code without changing its external behavior.) Initially in the .NET Framework, factoring was a non-issue because of the assumption that that it will always be deployed as one single unit. Through contracts, proper rules for versioning are followed and new APIs can also be added resulting in a newer version of that assembly. Contracts are being used across all the platforms which makes it a piece of cake for every platform to pick and choose the contracts that they want added to support them with a condition that the platform must support the vertical either as a whole or must not support it at all. The contents cannot be further broken down into subsets.

This aspect of contracts provides the concept of libraries that can target multiple platforms or verticals. This concept is also known as portable class libraries.

.NET Core revolution

All the aspects discussed and the failure of sharing code across verticals caused the .NET team to rethink into the modelling of the .NET platform for future. By rolling out .NET Core, Microsoft has introduced a revolution in the world of open source programming. It is a new fork and a modular version of the .NET framework designed to be portable across the verticals to maximize code sharing and reuse. The cherry on top of the cake is that it has been release as an Open Source and will accept the open-source community’s contributions for continuous improvements and further development.

.NET Core can be deployed modularly and locally both, with the support by Microsoft on the Windows, Linux and Mac OSX platforms. It targets both the traditional desktop Windows as well as Windows devices and phone. .NET Core provides portability to iOS and Android devices also using third-party tools such as Xamarin.

.NET Core introduces a common layer known as the Unified Base Class Library (BCL) which sits on top of the thin layer of Runtime. The API surface area is same for .NET Core and .NET Native. There are basically two implementations: .NET Native Runtime and CoreCLR which is specific to ASP .NET 5. The majority of the APIs are the same – they just don’t seems similar only but they also share the same implementation. For example, there need not be different implementations for collections.




So, what is .NET Core again? It is a modular framework accessible across platforms because it is a refactored set of base class libraries (CoreFX) and Runtime (CoreCLR). Along with that you can also have your own out-of-band libraries. This is also a key characteristic of .NET Core where you may choose the package you need to deploy with your app. This means that your apps can be deployed and run in isolation and machine-wide versions of the full .NET Framework do not cause a hindrance in the running of your apps.

Developing with .NET Core – from code to deployment

Let’s understand .NET Core and .NET Native through an example as technology can be better understood through implementation. We will have a mental walk through of a program through the help of a diagram instead of actual code here to understand the how the architecture and process works till the deployment of the program. The deployment and execution differs depending on your choice of app model that you are targeting.



After you write your code taking very modular references to parts of BCL and App Model that you need, the compiler compiles that code into an independent intermediate language (IL). There are also other sorts of APIs that can be used to do all sorts of analysis on your code including a wide variety of new IDE features available if you are using visual studio for the utilization of these APIs.

.NET Native runtime will continue the chain of coding to deployment if you’re targeting a Universal Windows App. References are built into your app and it comes out as one native dll deployed locally with a minimal runtime. ASP .NET 5 app takes you to the chain of .NET Core where CoreCLR and the references are deployed with your app locally to the server. Just-in-Time compilation then happens on startup. With ASP .NET 5 and CoreCLR you need no re-build your project every time you make some changes into it.

Summary

.NET Core platform is a new fork of the .NET Framework which aim to provide code reusability and to maximize code sharing across all set of verticals in the framework as a whole. It is an open-source platform which accepts contributions from the open source community to achieve their goal of constant improvement and optimization.

It is also important to note that .NET Core does not support for desktop which still requires the .NET Framework to be used at present but there is a promise of console application APIs to be available soon for users though there isn’t a set timeline for its release at the moment. You will also need to download Visual Studio 2015 edition to get the full experience of the new era of revolution in the open-source arena of the development world.