Monday 22 April 2013

Understanding .NET Architectire


.NET Framework

The .NET Framework (pronounced dot net) is asoftware framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a largelibrary and provides language interoperability (each language can use code written in other languages) across several programming languages. Programs written for the .NET Framework execute in a softwareenvironment (as contrasted to hardware environment), known as the Common Language Runtime (CLR), anapplication virtual machine that provides services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework.
The .NET Framework's Base Class Library provides user interface, data access, database connectivity,cryptography, web application development, numericalgorithms, and network communications. Programmers produce software by combining their own source codewith the .NET Framework and other libraries. The .NET Framework is intended to be used by most new applications created for the Windows platform. Microsoft also produces an integrated development environment largely for .NET software called Visual Studio.
.NET Framework

Initial release
13 February 2002; 11 years ago
4.5 (4.5.50709) / 15 August 2012; 8 months ago
Windows 98 or later,Windows NT 4.0 or later
Website



















Overview of .NET Framework release history
Generation
Version number
Release date
Notes
Development tool
Distributed with
1.0.3705.0
2002-02-13
original version
N/A
1.1.4322.573
2003-04-24
first update
2.0.50727.42
2005-11-07
rewrite of framework
3.0.4506.30
2006-11-06
WCF,WPF,WF
3.5.21022.8
2007-11-19
LINQ
4.0.30319.1
2010-04-12
parallel extensions
N/A
4.5.50709.17929
2012-08-15
asynchronous programming model

Design features
Interoperability
Because computer systems commonly require interaction between newer and older applications, the .NET Framework provides means to access functionality implemented in newer and older programs that execute outside the .NET environment. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices namespaces of the framework; access to other functionality is achieved using the P/Invoke feature.
Common Language Runtime engine
The Common Language Runtime (CLR) serves as the execution engine of the .NET Framework. All .NET programs execute under the supervision of the CLR, guaranteeing certain properties and behaviors in the areas of memory management, security, and exception handling.
Language independence
The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other conforming to the Common Language Infrastructure (CLI) specification. Because of this feature, the .NET Framework supports the exchange of types and object instances between libraries and applications written using any conforming .NET language.
Base Class Library
The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes that encapsulate a number of common functions, including file reading and writing, graphic rendering,database interaction, XML document manipulation, and so on. It consists of classes, interfaces of reusable types that integrates with CLR(Common Language Runtime).
Simplified deployment
The .NET Framework includes design features and tools which help manage the installation of computer software to ensure it does not interfere with previously installed software, and it conforms to security requirements.
Security
The design addresses some of the vulnerabilities, such as buffer overflows, which have been exploited by malicious software. Additionally, .NET provides a common security model for all applications.
Portability
While Microsoft has never implemented the full framework on any system except Microsoft Windows, it has engineered the framework to be platform-agnostic,[3] and cross-platform implementations are available for other operating systems (see Silverlight and the Alternative implementations section below). Microsoft submitted the specifications for the Common Language Infrastructure (which includes the core class libraries, Common Type System, and the Common Intermediate Language),[4][5][6] the C# language,[7] and the C++/CLI language[8] to both ECMA and the ISO, making them available as official standards. This makes it possible for third parties to create compatible implementations of the framework and its languages on other platforms.

.NET Framework 4.0 supports 96 languages....

Understanding the .NET Platform and its layers

Here in this section we will be covering what the .NET Platform is made up of and we will define its layers. To start, .NET is a framework that covers all the layers of software development above the Operating System. It provides the richest level of integration among presentation technologies, component technologies, and data technologies ever seen on Microsoft, or perhaps any, platform.
Secondly, the entire architecture has been created to make it easy to develop Internet applications, as it is to develop for the desktop. Constituents of .NET Platform
The .NET consists of the following three main parts
§  NET Framework – a completely re-engineered development environment.
§  NET Products – applications from MS based on the .NET platform, including Office and Visual Studio.
§  NET Services – facilitates 3rd party developers to create services on the .NET Platform
Description: dotnetfw
The above diagram gives you an overview of the .NET architecture. At the bottom of the diagram is your Operating System above that sits the .NET framework that acts as an interface to it. The .NET wraps the operating system, insulating software developed with .NET from most operating system specifics such as file handling and memory allocation.
The Common Language Runtime (CLR) At the base is the CLR. It is considered as the heart of the .NET framework. .NET applications are compiled to a common language known as Microsoft Intermediate Language or “IL”. The CLR, then, handles the compiling the IL to machine language, at which point the program is executed. The CLR environment is also referred to as a managed environment, in which common services, such as garbage collection and security, are automatically provided.

Languages

The CLR allows objects created in one language be treated as equal citizens by code written in a completely different language. To make this possible, Microsoft has defined a Common Language Specification (CLS) that details for compiler vendors the minimum set of features that their compilers must support if they are to target the runtime. Any language that conforms to the CLS can run on the CLR. In the .NET framework, Microsoft provides Visual Basic, Visual C++, Visual C#, and JScript support.

.NET Runtime

Description: clr
The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier. Compilers and tools expose the runtime’s functionality and enable you to write code that benefits from this managed execution environment. Code developed with a language compiler that targets the runtime is called managed code. To enable the runtime to provide services to managed code, language compilers must emit metadata, which the runtime uses to locate and load classes, lay out instances in memory, resolve method invocations, generate native code, enforce security, and set run-time context boundaries. The runtime automatically handles objects, releasing them when they are no longer being used. Objects whose lifetimes are managed in this way are called managed data. Automatic memory management eliminates memory leaks as well as many other common programming errors. The CLR makes it easy to design components and applications whose objects interact across languages. For example, you can define a class and then use a different language to derive a class from your original class, or call a method on the original class. You can also pass an instance of a class to a method on a class written in a different language. This cross-language integration is possible because of the common type system defined by the runtime, and they follow the runtime’s rules for defining new types, as well as for creating, using, persisting, and binding to types. Language compilers and tools expose the runtime’s functionality in ways that are intended to be useful and intuitive to their developers. This means that some features of the runtime might be more noticeable in one environment than in another. How you experience the runtime depends on which language compilers or tools you use.
The following benefits of the runtime might be particularly interesting to you:
§  Performance improvements.
§  The ability to easily use components developed in other languages.
§  Extensible types provided by a class library.
§  A broad set of language features.
Microsoft .NET Framework
The Microsoft .NET Framework is a computing model that make things easier for application development for the distributed environment of the Internet. The .NET Framework is an environment for building, deploying, and running Web Services and other applications. The key components of the .NET Framework are the CLR and the .NET Framework class library. The .NET Framework is a managed, type safe, multi-language environment for application development and execution.

.NET Framework is a set of core technologies that facilitates:
  • Easier application development, deployment and maintenance by providing rich tools, enhanced IDE, Better run time services etc.
  • Make information available anytime, anywhere and helps in developing better distributed applications via Web Services, ADO.NET DataSets and complete XML support.
With .NET, you can develop various types of applications as follows:

  • Windows Form based applications (Rich client applications).
  • Console based applications.
  • ASP.NET Web applications (Browser based applications).
  • Web services (Programmable application component that provides some useful functionality, such as application logic, and is available to any number of potentially incongruent systems through the use of Internet standards such as XML and HTTP).
  • Component Libraries (Components which encapsulate some business logic).
  • Windows Custom Controls (Your own windows controls).
  • Web Custom Controls (Your own web controls).
  • Windows Services (Applications that run as services in the background).
Overall architecture of the .NET Framework:Description: http://arunmicrosystems.netfirms.com/ganesh_.netguide_fig02.gif

CLR - CTS - CLS
The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (similar to the Java Virtual Machine or JVM in Java), which handles the execution of code and provides useful services for the implementation of the program.
The Common Language Runtime is the underpinning of the .NET Framework. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging.
Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.
The Common Language Specification (CLS) is an agreement among language designers and class library designers to use a common subset of basic language features that all languages have to follow.
CLR Execution Model:
Description: http://arunmicrosystems.netfirms.com/ganesh_.netguide_fig12.gif


DOTNET Framework

Languages supported by DOT NET:

DOT NET supports more than 50 languages. Some of them are listed below:
C++, C#, Visual Basic, Dr. Scheme, Pascal, Java, Javascript, J#, JScript, Cobol, PHP, Prolog, Ruby, Scala, Fortran,  Flash, Basic, Assembly, ADA, APL, Curriculum, Eiffel, Forth, Haskel, Mercury, Mondrian, Oberon, Oz, Perl, Python, RPG, SmallTalk, Standard ML, Lexico, LISP, SML, Spry, Synergy, Zoon, Processing, Pan, Nemerle, Modula -2, Lua, Logo, Cobra, Clarion, CAT, Caml, ASML, BETA, BF, Boo.......

How does DOT NET support/manage so many languages?

We will have to understand the DOTNET Framework for answer of the above query.

CLR: Common Language Runtime:

It is the programming environment which manages the execution of programs written in any of several supported languages by dotnet. It allows them to share common object-oriented classes written in any of the languages. The Common Language Runtime is somewhat comparable to the Java Virtual Machine that Sun Microsystems furnishes for running programs compiled from the Java language. Microsoft refers to its Common Language Runtime as a "managed execution environment." Some other tasks performed by CLR:

Garbage Collector
Permission and policy-based security
Exceptions
Threading
Diagnostics and profiling


How is CLR able to run so many languages?
We will have to understand CLR Execution Model for answer of the above query.

Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution. Following are some of the functions performed by CTS:

1. Common Types are mapped to types across all languages. For example: Byte, Sbyte, Single, Double, String, Int16, etc. are mapped to the common type system.

Example: In some of the languages, we declare integer as int, integer. But CTS converts it into Integer32.

2. Value Types are stored in Stack and Reference Types are store in Heap.

3. Boxing (Value Type to Reference Type) \ UnBoxing (Reference Type to Value Type).

Common Language Specification (CLS) is an agreement among language designers and class library designers to use a common subset of basic language features that all languages have to follow. In simple words, we can define this term as 'Set of Rules' which a language must follow to run on DOTNET framework

When we write our code in any of the supported languages by DOTNET, The CTS examines the code against CLS and then converts it into an intermediate language called MSIL (Microsoft Intermediate Language). Now JIT(Just In Compiler) takes that MSIL code and converts it into Machine code.

What is MSIL, IL?

When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.

What is CLR, MSIL, CLS, CTS ??????????

CLR it is Common Language Runtime
It provides Services like
*Automatic Memory Management
*Thread Management
*Code Compilation & Execution
*Code Verification
*High level of security
*Structured Exception Handling
*Interoperability between Managed and Unmanaged code.
MSIL-MicroSoft INtermediate Language also called IL or CIL
It is a Language Independent
After Compiling the Source Code The CLR gives MSIL code
By using JIT compiler it converts into Native Code
CTS-Common Type System.It Provides the common data types to the compiler.
CLS-Common Language Specification.It has a set of rules to provide the Language Interaperability.And it is a subset of CTS

A Brief Introduction To IL code, CLR, CTS, CLS and JIT In .NET

Before explaining these terminologies, I would like to explain how .NET code gets compiled. The developer writes source code in any .NET language i.e. it may VB.NET or C# or VC+++.NET, etc. The source code is compiled to Intermediate code known as IL code by the respective compilers for example for C# it is csc.exe compiler, for VB.NET it is vbc.exe compiler, etc. This half compiled code is then given to JIT(just in time compiler) by CLR which converts IL code to machine specific instructions which then gets executed. In this way a .NET code gets compiled. For better understanding have a look to following diagram :
Description: IC15013
Now we ll have a close look to above terminologies one by one. We will start from IL code.
·         IL Code : The word IL Code stands for Intermediate Language Code. It is a CPU independent partially compiled code. When we develop our .NET  application, we don’t know in what kind of environment our code will run i.e. on which operating system it will be finally hosted, what will be the CPU configuration, etc. So for this purpose we have IL code which is compiled according to machine configuration. IL code is given by Language compiler which is different for different languages for example csc.exe compiler for C#, vbc.exe compiler for VB.NET, etc.
·         CLR : CLR stands for Common Language Runtime. It is the heart of our .NET Framework. CLR performs following tasks :
1.         Garbage Collection : When we run our .NET application, many objects are created. Garbage collection is a background process which deletes the objects which are not in use by the application and frees memory.
2.         Code Access Security(CAS) and Code Verification(CV) : CLR checks the whether the code has access rights and it is safe and authenticated to be used.
3.         IL to Native Translation : The main task of CLR is to provide IL code to JIT to ensure that code is fully compiled as per machine specification.
·                 CTS : CTS stands for Common Types System. In .NET we have various languages like C#, VB.NET, etc. There may be many situations where we want code written in one language to be used in another. In order to ensure that we have a smooth communication between different languages, we have CTS. CTS ensures that datatypes defined in two different languages get compiled to a common data type so that code written in one language can be used by another.
·                 CLS : CLS stands for Common Language Specifications. It is a subset of CTS. CLS is a set of rules or guidelines which if followed ensures that code written in one .NET language can be used by another .NET language. For example one rule is that we cannot have member functions with same name with case difference only i.e we should not have add() and Add(). This may work in C# because it is case-sensitive but if try to use that C# code in VB.NET, it is not possible because VB.NET is not case-sensitive.
·                 JIT : JIT stands for Just In Timer Compiler. It is the internal compiler of .NET which takes IL code from CLR and executes it to machine specific instructions.



No comments:

Post a Comment