Basic of .Net Framework
Basic of .Net Framework
NET FRAMEWORK
The Microsoft .Net Framework is a platform that provides tools and technologies you
need to build Networked Applications as well as Distributed Web Services and Web
Applications. The .Net Framework provides the necessary compile time and run-time
foundation to build and run any language that conforms to the Common Language
Specification (CLS).The main two components of .Net Framework are Common
Language Runtime (CLR) and .Net Framework Class Library (FCL).
The Common Language Runtime (CLR) is the runtime environment of the .Net
Framework , that executes and manages all running code like a Virtual Machine.
The .Net Framework Class Library (FCL) is a huge collection of language-
independent and type-safe reusable classes. The .Net Framework Class Libraries
(FCL) are arranged into a logical grouping according to their functionality and
usability is called Namespaces. In the following sections describes how to .Net
Framework manages the code in compile time and run time .
CLR
The .Net Framework class library (FCL) organized in a hierarchical tree structure and
it is divided into Namespaces. Namespaces is a logical grouping of types for the
purpose of identification. Framework class library (FCL) provides the consistent base
types that are used across all .NET enabled languages. The Classes are accessed by
namespaces, which reside within Assemblies. The System Namespace is the root for
types in the .NET Framework. The .Net Framework class library (FCL) classes are
managed classes that provide access to System Services . The .Net Framework class
library (FCL) classes are object oriented and easy to use in program developments.
Moreover, third-party components can integrate with the classes in the .NET
Framework.
CLS
Common Language Specification (CLS) is a set of basic language features that .Net
Languages needed to develop Applications and Services , which are compatible with
the .Net Framework. When there is a situation to communicate Objects written in
different .Net Complaint languages , those objects must expose the features that are
common to all the languages . Common Language Specification (CLS) ensures
complete interoperability among applications, regardless of the language used to
create the application.
CTS
Common Type System (CTS) describes a set of types that can be used in different
.Net languages in common . That is , the Common Type System (CTS) ensure that
objects written in different .Net languages can interact with each other. For
Communicating between programs written in any .NET complaint language, the types
have to be compatible on the basic level .
These types can be Value Types or Reference Types . The Value Types are passed
by values and stored in the stack. The Reference Types are passed by references
and stored in the heap. Common Type System (CTS) provides base set of Data
Types which is responsible for cross language integration. The Common Language
Runtime (CLR) can load and execute the source code written in any .Net
language, only if the type is described in the Common Type System (CTS) .Most
of the members defined by types in the .NET Framework Class Library (FCL) are
Common Language Specification (CLS) compliant Types.
MSIL
MSIL stands for Microsoft Intermediate Language. We can call it as Intermediate
Language (IL) or Common Intermediate Language (CIL). During the compile time ,
the compiler convert the source code into Microsoft Intermediate Language
(MSIL) .Microsoft Intermediate Language (MSIL) is a CPU-independent set of
instructions that can be efficiently converted to the native code. During the runtime
the Common Language Runtime (CLR)'s Just In Time (JIT) compiler converts the
Microsoft Intermediate Language (MSIL) code into native code to the Operating
System.
The PE file format was defined to provide the best way for the Windows Operating
System to execute code and also to store the essential data which is needed to run a
program. Portable Executable File Format is derived from the Microsoft Common
Object File Format (COFF).
The Common Language Runtime (CLR) provides various Just In Time compilers
(JIT) and each works on a different architecture depending on Operating System. That
is why the same Microsoft Intermediate Language (MSIL) can be executed on
different Operating Systems without rewrite the source code. Just In Time (JIT)
compilation preserves memory and save time during application initialization. Just In
Time (JIT) compilation is used to run at high speed, after an initial phase of slow
interpretation. Just In Time Compiler (JIT) code generally offers far better
performance than interpreters.
MANAGED CODE IN .NET FRAMEWORK
METADATA
ASSEMBLY
Microsoft .Net Assembly is a logical unit of code, it contains code that the Common
Language Runtime (CLR) executes. Assembly is really a collection of types and
resource information that are built to work together and form a logical unit of
functionality. During the compile time Metadata is created, with Microsoft
Intermediate Language (MSIL), and stored in a file called a Manifest . Both Metadata
and Microsoft Intermediate Language (MSIL) together wrapped in a Portable
Executable (PE) file. Manifest contains information about itself. This information is
called Assembly Manifest, it contains information about the members, types,
references and all the other data that the runtime needs for execution.
Every Assembly you create contains one or more program files and a Manifest. There
are two types program files : Process Assemblies (EXE) and Library Assemblies
(DLL). Each Assembly can have only one entry point (that is, DllMain, WinMain, or
Main). We can create two types of Assembly, private Assembly and shared
Assembly . A private Assembly is used only by a single application, and usually it is
stored in that application's install directory. A shared Assembly is one that can be
referenced by more than one application. If multiple applications need to access an
Assembly, we should add the Assembly to the Global Assembly Cache (GAC).
GAC(GLOBAL ACCESS CACHE)
Each computer on which the Common Language Runtime is installed has a machine-
wide code cache called the 'Global Assembly Cache'. The Global Assembly Cache
(GAC) enables you to share assemblies across numerous applications.
The GAC is automatically installed with the .NET runtime. The global assembly
cache is located in 'Windows/WinNT' directory and inherits the directory's access
control list that administrators have used to protect the folder.
The approach of having a specially controlled central repository addresses the shared
library concept and helps to avoid pitfalls of other solutions that lead to drawbacks
like DLL hell.
The Global Assembly Cache Tool (Gacutil.exe), that allows you to view and
manipulate the contents of the Global Assembly Cache.
CONTENT OF AN ASSEMLY
A .NET assembly can consist of following elements:
a) Assembly Manifest - The Metadata that describes the assembly and its contents
Only the assembly manifest is required, but either types or resources are needed to
give the assembly in any meaningful functionality.
PRIVATE AND SHARED ASSEMBLY
In order to share an assembly, the assembly must be explicitly built for this purpose
by giving it a cryptographically strong name . By contrast, a private assembly name
need only be unique within the application that uses it.
The classes that ship with the .NET Framework are all built as shared assemblies.
NAMESPACES
Namespaces are the way to organize .NET Framework Class Library into a logical
grouping according to their functionality, usability as well as category they should
belong to, or we can say Namespaces are logical grouping of types for the purpose of
identification.
The .Net Framework provides a new mechanism for releasing unreferenced objects
from the memory (that is we no longer needed that objects in the program) ,this
process is called Garbage Collection (GC). When a program creates an Object, the
Object takes up the memory. Later when the program has no more references to that
Object, the Object's memory becomes unreachable, but it is not immediately freed.
The Garbage Collection checks to see if there are any Objects in the heap that are no
longer being used by the application. If such Objects exist, then the memory used by
these Objects can be reclaimed. So these unreferenced Objects should be removed
from memory , then the other new Objects you create can find a place in the Heap.