.NET Framework At A Glance

The Philosophy of .NET

C# programming language and the .NET platform were introduced by Microsoft in 2002 and have quickly become a need for modern-day software development.

Initial look at the .NET Platform

Before .NET, Windows programming using the Microsoft platform was divided into a number of branches. At that time, C, C++, and Visual Basic were used. Some C and C++ programmers were using raw win32 API and most of the programmers were using MFC (Microsoft Foundation Classes), while the others had moved to COM.

Despite the complexity and limitations of COM, countless applications have been successfully created with this architecture. But nowadays, desktop applications, web applications, OS Services, and libraries of reusable data access/business logic are created using them. NET.

What is the .NET Framework?

  • “.NET framework is a software platform designed to build systems on Windows, Mac OS, and Linux/Unix distributions.”
  • “NET framework is the managed code and platform-independent programming model. It provides a highly productive environment for software developers and offers excellent skills reuse across multiple application architectures.”

Some Key Benefits of the .NET Platform

.NET framework was designed to address the problems and limitations faced by old programming techniques. Some of the key benefits of the .NET framework are mentioned below.

  • Multiple Platforms: It runs on a broad range of computers from Servers and desktop machines to PDAs and cell phones.
  • Security: It provides a much safer execution environment even in the presence of the code obtained from the suspect source.
  • Interoperability with existing code: A program written in one .NET language can be used and even inherited from the class written in another .NET language.
  • Platform Invoke: .NET Framework provides a feature called platform invoke (P/Invoke) which allows you to use code written for .NET in code not written in. NET.
  • Interoperability with COM: The .NET framework provides interoperability with COM. COM components can call .NET components and .NET components can call COM components.
  • Support for numerous languages: .NET application can be written in any number of programming languages for example (C#, Python, F#, VB.NET, etc.).
  • Communication using Industry Standards: The system uses industry-standard communication protocols such as HTTP, SOAP, XML, WSDL, and JSON.
  • Object-Oriented Development Environment: The CLR, BCL, and C# are designed to be object-oriented and act as a well-integrated environment.
  • Simplified Development: .NET libraries are not registered in the registry. In addition, .NET allows multiple versions of the same .dll to exist on a machine.

Introducing CLR, CTS, and CLS

  1. From a programmer’s point of view, .NET can be understood as a runtime environment and a comprehensive base class library. The runtime environment is known as Common Language Runtime (CLR). The primary role of CLR is to manage, load, and locate .NET objects on your behalf. CLR also takes care of memory management, application hosting, and thread management, and performs basic security features.
  2. Another block of .NET framework is the Common Type System (CTS). The CTS describes all possible data types and all programming constructs supported by runtime. (Scroll down for more information on CTS).
  3. A .NET-aware language might not support every features defined by the CTS. The Common Language Specification CLS is a specification that defines a subset of common types and programming constructs that all .NET programming languages can agree on. So, if you build a .NET type that follows only CLS features, then you can assure that every .NET aware language can use them. Or, if you are using data type or programming construct that is outside of the specifications of the CLS, you cannot guarantee that every .NET programming language can interact with your code.

Role of Framework Class Library (FCL)

  1. .NET framework provides an extensive library called Base Class Library which is sometimes also called Framework Class Library (FCL). You can use these libraries when writing your programs some of them are XML classes, collection classes, threading and synchronization classes etc. Not only does BCL provide collection of classes, but it also provides support for services required by applications.
  2. You can use these libraries to build any type of software application. For example, you can use ASP.NET to build web-based applications, REST services, WCF to build distributed systems, WPF to build desktop applications etc.
  3. You can use these libraries to build any type of software application. For example, you can use ASP.NET to build web-based applications, REST services, WCF to build distributed systems, WPF to build desktop applications etc.

 .NET Framework

The CLR, CTS, CLS, and base class library relationship.

Library relationship

What Makes C# a Popular Programming Language?

C# programming language is written in C and C++ whose syntax is similar to the syntax of JAVA. However, calling C# a copy or duplicate of Java is inaccurate. C# and java, both belong to the C family. Here is the list of core C# features that are found in all versions of the language.

  • No pointers are required.
  • Automatic memory management through garbage collection.
  • Constructs according to the syntax for classes, delegates, interfaces, structs, and enumerations.
  • Ability to overload operators like C++, without complexity.
  • Support for attribute-based programming.

With the release of .NET 2.0 in 2005, more functionalities were added in C#.

  • The ability to build generic types and generic members.
  • Support for anonymous methods.
  • Ability to define single type across multiple code files using the partial

.NET 3.5 (released in 2008) added even more functionality to the C# programming language.

  • Support for strongly typed queries (LINQ).
  • Support for extension methods.
  • Addition of Lambda expression, which simplifies working with delegates.

.NET 4.0 (released in 2010) updated C# with more features.

  • Support for optional method parameters as well as named method arguments.
  • Support of Dynamic
  • COM interop.

.NET 4.5 added more functionality to the C# programming language.

  • Inline initialization for automatic properties as well as support for read-only automatic properties.
  • Support for static which provides direct access to the static members within a namespace.
  • A null conditional operator helps check for null parameters in a method.
  • Support for string interpolation.
  • Ability to filter exceptions using the when

Managed vs. Unmanaged Code

C# can only be used to build software that runs under the .NET framework. You can never use C# to build C or C++-style applications. The code that runs under the Common Language Runtime (CLR) is managed code, or the code targeting the .NET runtime is managed code. The code is not hosted under the .NET framework or not targeted to the .NET framework is unmanaged code. Managed code is stored in the binary unit called assembly. This environment makes it possible to build .NET programs on a wide variety of machines.

Unmanaged Code
Image Link: https://i-msdn.sec.s-msft.com/dynimg/IC104620.jpeg

.NET Assemblies

.NET binaries contain IL (Intermediate Language) and type metadata. IL is also known as MSIL (Microsoft Intermediate Language) or alternatively as CIL (Common Intermediate Language). They do not contain platform-specific information. Remember that .NET libraries have the same file extensions as unmanaged Windows libraries (.dll and .exe).

.NET Assemblies

The compiler for a .NET language takes a source code file and produces an output file called an assembly. The code in an assembly is not native machine code but CIL. When a .dll or .exe file has been created using any .NET language compiler, that binary file is known as assembly. As assembly contains CIL code, this is conceptually simple as Java bytecode. In that, it is not compiled to platform-specific instruction until necessary. In addition, CIL also contains metadata that describes characteristics of every type within the binary.

CIL, type metadata, and assemblies themselves are also described using metadata which is termed as manifest. The manifest contains information about the current version of the assembly, the culture information, and all externally referenced assemblies that are required for execution.

Compiling to Native Code and Execution

The program does not comply with native machine code until it is called to run. CLR manages the program’s execution at runtime and performs the following steps.

  • It checks the security characteristics of the assembly.
  • It allocates space in memory.
  • It sends the CIL to the just-in-time (JIT) compiler which compiles it to native code.

The JIT compiler the CIL code in the assembly and only when needed and it’s then cached. The code that is not called during execution is not compiled into native code. The code that is called needs only to be compiled once.

 .NET Framework

Compilation occurs at runtime.

Once CIL is compiled to native code, CLR manages it at runtime and perform tasks such as checking parameters, checking array bounds, and exception handling, etc.

Figures Shows Compile-Time and Runtime Processes.

Compile-Time

The Role of the Assembly Manifest

As I described above, the assembly also contains metadata that describes the assembly itself which is termed as manifest. Among other details all external assemblies are required by the current assembly to perform correctly, the assembly version number, copyright information, etc. The compiler is responsible for generating the assembly’s manifest. Here is an example of the manifest generated by the compiler when compiling the Example. cs.

.assembly extern mscorlib
{
    .publickeytoken = (A1 2B 3C 45 67 89 D0 1E)
    .ver 4:0:0:0
}
.assembly Example
{
    .hash algorithm 0x00008004
    .ver 0:0:0:0
}
.module Example.exe
.imagebase 0x00400000
.subsystem 0x00000003
.file alignment 0x00000200
.corflags 0x00000001

The Common Type System (CTS)

The Common Type System (CTS) defines the characteristics and types that must be used in the managed code. CTS defines how types are declared, used, and managed in the Common Language Runtime (CLR). The CTS performs the following functions.

  • Establish a framework that helps enable cross-language integration, type safety, and high-performance code execution.
  • Provides an object-oriented model that supports the complete implementation of. NET-aware programming languages.
  • Defines rules that all. NET-aware languages must follow, which helps to ensure that objects written in different languages can interact with each other.
  • Provides a library that contains primitive data types such as Boolean, ByteCharInt32, and UInt64.

CTS is a formal specification that documents how types must be defined in order to be hosted by the CLR. It is important to learn how to work with five types defined by the CTS. One of the most important characteristics of CTS is that all types are derived from a common base class called System. Object.

Types in the .NET Framework

The common type system in the .NET Framework supports the following five categories of types.

  • Class
  • Struct
  • Interface
  • Delegate
  • Enum

Data Types in the .NET Framework

Data type

The Common Language Specification (CLS)

The CLS specifies the rules, properties, and behaviors of a . NET-compliant programming language. The topics include data types, class construction, and parameter passing.

The Common Language Runtime

CLR can be understood as a collection of services that are required to execute a given compilation of code. CLR is a core component of the .NET framework which sits on the top of the operating system and manages the program’s execution. CLR also performs the following services,

  • Garbage collection
  • Memory management
  • Managing exceptions
  • Security and authentications
  • Thread management

    Thread management

Resources for this post.


Similar Articles