The .NET Framework consists of the common language runtime and the .NET Framework class library.
The common language runtime is the foundation of the .NET Framework. CLR is responsible for services such as
- memory management
- thread management
- automatic garbage collection
- enforcing strict type safety constraints that promote security.
The code developed in Dot net Framework is thus more robust and is known as managed code while the code developed in an external application and later imported in Dot net Framework does not have the intrinsic security provided to the Managed code by CLR and is known as unmanaged code. The class library is a collection of reusable types that you can use to develop applications ranging from traditional console driven or graphical user interface (GUI) applications to Web applications and Mobile apps based on the latest technology by ASP.NET.
Components of .NET Framework:-
1.Common Language Runtime (CLR)
.Net Framework provides runtime environment called Common Language Runtime (CLR).It introduces an interesting concept called managed code which performs tasks to improve the quality and performance of the source code written in Dot Net environment to run all the .Net Programs. The developers do not need to manage garbage values or data getting corrupt due to overlapping memory between two applications through their code. It provides memory management, thread management and automatic garbage collection.We will talk about CLR in detail in our next few posts.
2.Metadata
.NET metadata for an application, in the Microsoft .NET framework, refers to certain data structures embedded within the Microsoft Intermediate Language code which determines the type of compiler required to compile the application and classes to be loaded. Metadata describes data about data .It has information about all data that are defined in the assembly. A .NET language compiler will generate the metadata and store this in the assembly containing the MSIL. When the CLR executes MSIL it will check to make sure that the metadata of the called method is the same as the metadata that is stored in the calling method. This ensures that a method can only be called with exactly the right number of parameters and exactly the right parameter types.
3. Assemblies
- Microsoft .Net Assembly is the smallest unit of deployment of a .net application .
- It include both executable application files that you can run directly from Windows without the need for any other programs (.exe files), and libraries (.dll files) for use by other applications.
- Assemblies are the building blocks of .NET Framework applications.
- During the compile time data is created for tracking ,identifying and describing each program.
- This data also known as Metadata is created with Microsoft Intermediate Language (MSIL) and stored in a file called Assembly Manifest .
- Both Metadata and Microsoft Intermediate Language (MSIL) together wrapped in a Portable Executable (PE) file.
- The Assembly Manifest, contains information about the members, types, references and all the other data that is needed for the execution of program during run time. Every Assembly created contains one or more program files and a Manifest.
Why assemblies are necessary?
The assemblies in Dot Net are used to prevent the problem of DLL Hell is a set of errors thrown due to multiple software programs or applications attempting to register a DLL dynamic link library (DLL) with the same name. The reason for this issue was that the version information about the different components of an application was not recorded by the system. During the installation of an application the dll of that application get stored in the registry, then if we install other application that has same name .dll that means previously installed .dll get overwritten by the same name new .dll. So the previously installed application cannot be executed any more due to the missing DLL. This problem in context of version of same application is known as Dell-Hell. This problem of dynamic link library (.dll) is resolved through Versioning.
4.Framework Class Library(FCL)
Dot net supports more than 15 languages and provides a set of common class libraries used by the source code written in any of the supported language. The programmers trained in any one language of Dot net environment can switch to any other language with minimum training.
In short, developers just need to import the Base Class Library in their language code and use its predefined methods and properties to implement common and complex functions like reading and writing to file, graphic rendering, database interaction, and XML document manipulation.
For example The SQLClient class in Dot Net Framework is used for accessing database designed in SQL Server.
To perform database connection a comparison of code is shown in the following table.
VB.NET | C#.NET |
imports System.Data.SQLClient
private sub con dim cn as new SQLConnection cn=new SQLConnection(“Data Source=.\sqlexpress;Initial Catalog=employee;Integrated Security=True”) cn.open() end sub |
using System.Data.SQLClient;
private void con() {SQLConnection cn=new SQLConnection(@“Data Source=.\sqlexpress;Initial Catalog=employee; Integrated Security=True”); cn.open(); } |
5.Common Type System
Dot net has a generic type system which is common to all the languages supported in Dot Net framework.
- The Common type system is a standard that specifies how type definitions are represented in computer memory. It provides cross language inter operability.
- A program developed in Dot net framework is a collection of classes.
- Each class consists of data members and methods.
- The storage and retrieval of the data in an identifier is controlled through “Types”.
- C#.NET is a strongly “Typed” language. Thus all operations on variables are performed with consideration of what the variable’s “Type” is. Operands should normally be of the same type.
- For example, if you are doing subtraction with an Integer variable, you should subtract it from another Integer variable, and store the result to a variable of type Integer as well.
6.Application Domain:
Application domains provide a flexible and secure method of isolating running applications. An application domain provides application security by the common language runtime to provide isolation between applications. Several processes which need to communicate with each other can be executed in the same process and can be accessed without switching between processes. The ability to run multiple applications within a single process increases server scalability and efficiency of the server. Using application domains ensures that code running in one domain cannot affect other applications in the process.
7.Common Language Specification:
The .NET Framework includes classes, interfaces, and value types that provide access to system functionality. The CLS rules define a subset of the Common Type System with some stricter rules are defined in the CLS.Most .NET Framework types are CLS-compliant and can therefore be used from any programming language whose compiler conforms to the common language specification (CLS).
8.Managed Code and Unmanaged code
Dot NET supports two kind of coding
- Managed Code
- Unmanaged Code
Managed Code
The code, which is developed in .NET framework, is known as managed code. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code. Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross – language debugging, and so on.
Unmanaged Code
The code, which is developed outside .NET, Framework is known as unmanaged code.
- Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications.
- If you import a project developed in Visual Studio 6.0 in Visual Basic or VC++ in Visual Studio .net IDE,it is identified as an unmanaged code in Dot Net. Background compatibility with code of VB, ASP and COM are examples of unmanaged code.
- Dot Net provides wrapper classes and drivers for executing unmanaged code.
- Unmanaged code is not compiled by CLR .
- When we compile unmanaged code it gets compiled into a binary X86 image so it lacks the security features provided by CLR.It compiles straight to machine code and directly executed by the Operating System.
- The generated code runs on the host processor by the host compiler (e.g C++) and the processor directly executes the code generated by the compiler.
- It is always compiled into a target machine dependant code unlike the platform neutral code generated by Dot Net framework and will only run on the intended platform. So, if the code needs to be run on different architecture then it needs to be recompiled.