Overview Of .NET Framework

To work on ASP. NET and to understand the ASP. NET world, first we have to understand .NET Framework. It is a common question which is asked in interviews that "What is .NET Framework and the need of .NET Framework?"
As I know my friends and colleagues who are working as web developers also face problems with .NET Framework's questions. So, today I decided to write about the .NET framework.

.NET Framework

  1. .NET framework is a complete development and execution environment. That allows the developer to develop, run, and deploy the following application.
    1. Console application.
    2. Windows application
    3. Web application
    4. Service-oriented application (WCF)
    5. Web service
    6. Windows service
    7. WPF, WWF, etc.
  2. .NET Framework supports the object-oriented programming model for multiple languages such as C#, VB, vC++, J#, etc.
  3. It supports language interoperability. Interoperability implies that each language can use the code written in some other language.
  4. It provides a common set of tools and enables easy integration of modules developed with one another.
  5. It also enables the developers to create a shareable component to be used in distributed computing architecture.

Need for .NET Framework

.NET Framework was designed to fulfill the following goals.
  1. Interoperability
  2. Cross-platform Support
  3. Language Independence
  4. Base class library.
  5. Easy development f. Security
.NET Framework supports interoperability between new applications and existing applications. It implies that the code written in one language can be used in some other language.
Cross-Platform support
Each .NET compatible language, such as C#, VB, VC++ provides its own compiler to compile code to MSIL. After that, the common runtime engine compiles MSIL code to native code with the help of the Just In Time (JIT) compiler and then run the application.
Cross Platform
Language Independence
.NET framework provides multiple language support by using a feature known as a common type system. That is built into common language runtime.
Base Class Library
The base class library provides the fundamental building block for any application you develop. These applications could be windows, web, console, or service-oriented. The BCL mostly serves as the main point of interaction with the CLR.
Easy Deployment
.NET Framework makes the task of employment easier. In most cases, installing an application along with a component on the target computer is easier.
.NET Framework provides a security model that allows you to authorize and authenticate the user.

Component of .NET Framework

The following are the main components of the .NET Framework.
  1. .NET Framework library
  2. CLR
  3. DLR (Dynamic Language Runtime
  4. Application Domain
  5. Runtime host
  6. CTS ( Common Type System)
  7. Metadata
  8. Cross-Language Interoperability
  9. Security
  10. Side by side execution
  11. Profiling etc.
Above all components discussed separately in the next topic.
MSIL (Microsoft Intermediate Language) OR Intermediate Language( IL)
IL stands for Intermediate Language. It is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language ). All the .NET language such as C#, J#, VB uses their own compiler. The compiler compiles the code into IL and after thaT common runtime engine converts the IL code into native code with the help of the JIT compiler.
MSIL: .NET is shipped with a compiler of all programming languages to develop the program. There is a separate compiler for the VB, C#, VC++, etc. All compilers produce an intermediate code after compiling the source code. The intermediate code is common for all languages and it is understandable in a .NET environment. This intermediate code is known as IL or MSIL.
Assembly Manifest
Assembly manifest stores the assembly metadata. It contains all the metadata needed to do the following things:
  1. Version of assembly
  2. Security Identity
  3. Scope of assembly
  4. Resolve reference to the resource of class
Assembly manifest contains PE file either .exe or .dll
Common Type System
CTS is a component of CLR (Common Language Runtime) through which the .NET Framework provides support for multiple languages. Because it contains a type system, that is common across all the languages. Two common types of system languages do not require type conversion when calling the code written in another language. CTS provide a base set of data type for all languages supported by .NET framework. This means that the size of the integer and the long variable are the same across all languages.
Managed and Unmanaged code
  • Managed Code: Managed code is the code that executed directly by CLR instead of the operating system. The language compiler compiles the managed code to IL or MSIL. This code does not depend on the machine configuration and can be executed on a different machine. Managed code process is as follows:
    Choose Language Compiler --> Compile to MSIL, MSIL to Native Code, then Execute the code
  • Unmanaged Code: Unmanaged code is the code that is executed directly by the operating system outside the CLR environment. It is directly compiled to native machine code which depends on the machine configuration. In unmanaged code, the allocation of memory, Type safety, and security are required to be taken care of by the developer. If unmanaged code is not properly handled it may result in a memory leak.
Assembly in .NET framework
Every software has an executable file (.exe) apart from the .exe file, there is some dynamic link library (.dll) and Library file (.lib) that contains the compiled code of some commonly used function. These files are shipped along with the software. Any software package includes an executed file along with some DLL and LIB files that are necessary to run the application. In .NET runtime terms, the process of packing is called assembly. An assembly contains MSIL, Metadata file are required to execute a .NET program successfully. There are two types of assembly,
  1. Private Assembly
  2. Public assembly
Global Assembly Catch (GAC )
While using a shared assembly, to avoid assembly being overwritten by the different or same assembly. Shared assembly is placed in a special directory in the file system are known as global assembly catch.
GAC is a central repository (cache) in a system in which assemblies are registered to share among various applications that execute on local or remote machines. .NET Framework provides the GAC tool (gacutil.exe utility), which is used to view and change the content of the GAC of a system. Adding new assemblies to GAC and removing assemblies from GAC are some of the tasks that can be performed using the gacutil.exe utility. GAC can contain multiple versions of the same .NET assembly. CLR checks GAC for a requested assembly before using the information of configuration files.
Component and services of CLR
There are several components of CLR, which are as follows:
  1. CTS
  2. MSIL
  3. Execution Support Function
  4. Security
  5. Garbage collection
  6. Classloader
  7. Memory layout
Services of CLR
  1. Loading and execution of the program.
  2. Memory Isolation for application.
  3. Verification of type safety.
  4. Compilation of MSIL to native code.
  5. Providing Metadata.
  6. Interoperability with other systems.
  7. Managing exception and error.
  8. Debugging and profiling.
Garbage collection
Garbage collection prevents memory leaks during the execution of programs. It is a low priority process that manages the allocation and deallocation of memory in your application. It checks for unreferenced variables and objects. If GC finds any object that is no longer used by the application, it frees up the memory of that object.
GC has changed a bit in the .NET framework 4.0. It contains the following overload method,
  1. GC.collect ()
  2. GC.collect (int, GC collection method)
Generation of garbage collection
  1. Generation 0: When an object is initialized.
  2. Generation 1: The object under the GC process.
  3. Generation 2: Whenever a new object is created and added to memory. It adds generation 0 and generation 1.
Namespace in .NET framework
Namespace has two basic functionalities:
  1. It is a logical group type.
  2. In the object-oriented world many times it is possible that the programmer will use the same class name by qualifying namespace with the class name, this collision is able to remove.
Difference between Assembly and Namespace
  1. An assembly is a physical grouping of the logical unit while a namespace is a logical group of class.
  2. A namespace can span multiple assemblies.
  3. It is a collection of names wherein each name is unique. While assembly is an output unit it contains a unit of development and deployment.
Difference between private and shared assembly
Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name.