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 is working as a web developer also face problems on .NET Framework's questions. So, today I decided to write about .NET framework.
.NET Framework
- .NET framework is a complete development and execution environment. That allows the developer to develop, run and deploy the following application.
- Console application.
- Windows application
- Web application
- Service oriented application (WCF)
- Web service
- Windows service
- WPF, WWF etc.
- .NET framework support the object oriented programming model for multiple language such as, C#, VB, vC++, J#, etc.
- It support the language interoperability. Interoperability implies that each language can use the code written in some other language.
- It provides a common set of tools and enables easy integration of module developed with one another.
- It also enables the developers to create shareable component to be used in distributed computing architecture.
Need of .NET Framework
.NET Framework was designed to fulfill the following goals.
- Interoperability
- Cross platform Support
- Language Independence
- Base class library.
- Easy development f. Security
Interoperability
.NET Framework supports interoperability between new application and existing application. 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 compile MSIL code to native code with the help of Just In Time (JIT) compiler and then run the application.
Language Independence
.NET framework provides the multiple language support by using feature known as 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, to install an application along with component on the target computer is easier.
Security
.NET Framework provides 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.
- .NET Framework library
- CLR
- DLR (Dynamic Language Runtime
- Application Domain
- Runtime host
- CTS ( Common Type System)
- Metadata
- Cross Language Interoperability
- Security
- Side by side execution
- Profiling etc.
Above all components discussed separately in 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 there own compiler. The compiler compile the code into IL and after thaT common runtime engine convert the IL code into native code with the help of JIT compiler.
OR
MSIL: .NET is shipped with compiler of all programming language to develop program. There are separate compiler for the VB, C#, VC++, etc. All compilers produce an intermediate code after compiling source code. The intermediate code is common for all language and it is understandable into .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:
- Version of assembly
- Security Identity
- Scope of assembly
- Resolve reference to 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 .NET framework provide support for multiple language. Because it contains a type system, that is common across all the languages. Two common type system language 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 integer and long variable is same across all language.
Managed and Unmanaged code
- Managed Code: Managed code is the code that executed directly by CLR instead of operating system. The language compiler compile the managed code to IL or MSIL. This code does not depend on the machine configuration and can be executed on different machine. Managed code process are 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 is required to be taken care of by the developer. If unmanaged code is not properly handled it may result in memory leak.
Assembly in .NET framework
Every software has an executable file (.exe) apart from the .exe file, there are 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 file 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,
- Private Assembly
- Public assembly
Global Assembly Catch (GAC )
While using shared assembly, to avoid assembly being overwritten by the different or same assembly . Shared assembly are placed in a special directory in the file system are known as global assembly catch.
Or
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 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 information of configuration files.
Component and services of CLR
There are several component of CLR, which are as follows:
- CTS
- MSIL
- Execution Support Function
- Security
- Garbage collection
- Class loader
- Memory layout
Services of CLR
- Loading and execution of program.
- Memory Isolation for application.
- Verification of type safety.
- Compilation of MSIL to native code.
- Providing Metadata.
- Interoperability with other system.
- Managing exception and error.
- Debugging and profiling.
Garbage collection
Garbage collection prevent memory leaks during execution of programs. It is a low priority process that manages the allocation and deallocation of memory in your application. It checks for unreferenced variable and objects. If GC find any object that is no longer used by application, it frees up the memory that object.
GC has changed a bit in .NET framework 4.0. It contains the following overload method,
- GC.collect ()
- GC.collect (int, GC collection method)
Generation of garbage collection
- Generation 0: When an object is initialized.
- Generation 1: The object under the GC process.
- Generation 2: Whenever new object is created and added to memory. It adds generation 0 and generation 1.
Namespace in .NET framework
Namespace has two basic functionalities:
- It is a logically group type.
- In object oriented world many times it is possible that programmer will use the same class name by qualifying namespace with class name, this collision is able to remove.
Difference between Assembly and Namespace
- An assembly is a physical grouping of logical unit while namespace is logical group of class.
- A namespace can span multiple assembly.
- 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.