MS.NET Online training.
Online Training
MS.Net Online Training | C# Online Training | MVC,WPF,WCF Online Training in Hyderabad
Introduction to Microsoft.NET Framework
Objectives
· Why MS.NET?
· What is MS.NET?
· Overview MS.NET Architecture
· What is a Namespace?
· What is a framework?
· How MS.NET works?
· MS.NET Framework comparison chart
· Advantages of MS.NET
Introduction
Microsoft.NET is a platform that targets a programmer to design, develop and deploy an application of his choice could be a console, window or web
application. It is the first object oriented approach with Microsoft technologies. It provides a generic environment to develop an application irrespective of the domain. It leads to platform independence, language independence. It is majorly focused on Network Enabled technology could be internet or mobile. Microsoft believes distributed applications as future.
It’s important to understand that C#.net is not just a language to code internet or network applications.
It provides an object oriented approach to build software components that suit to any domain.
So what’s the big deal about .Net and their languages?
Why MS.NET?
Let’s understand generic and specific elements of real world in the following examples:
Example 1: College Library
In a college, we don’t find CSE/IT/ECE /EEE specific Library instead we have the Generic
centralized library. As we know few departments may have common subject to be dealt.
Here generic library provides more comfort than specific library in terms of organizing
and stay economic.
Example 2: Construction
if we observe a colony, we find two types of constructions – Independent and Apartment.
In an independent house, we confine that only one family reside, where as in an apartment
would reside at least a family. In an independent house all resources belong to one family
could be a TV, Dining Table, Car, Bore Well, Gym, Swimming pool. Whereas in an apartment
few resources are specific like – TV, Dining Table and Car whereas few resources are generic
like bore well, Gym, Swimming pool i.e. they are shared by all families in an apartment.
Here an apartment is more economical in terms to place and consume generic resources.
Example 3: Super Market
it’s week end I need to buy vegetables, dal, rice, trousers, etc. To complete my task I need to
travel rithu Bazaar to buy vegetables, and then travel to a ration shop to buy dal and rice, oil
finally I need to visit a shopping mall to buy trousers. Wish I could have a generic place like a
super market or Big bazaar where I can get all these shopping done at one place. It saves me
time and releases my stress.
How generic and specific concepts apply our need of MS.Net?
Microsoft put forward MS.NET to achieve the following:
· Convert specific data types to generic data types
· Convert specific functions to generic functions
· Convert specific library to generic library
· Convert specific compiled ASCII code to generic MSIL code
· Convert specific IDE’s to generic IDE (visual studio.NET)
· Convert specific domain development to generic domain development
Explanation
Scenario 1:
Let’s consider two programmers – C and C++. As a C programmer, I would include STDIO.H library and PRINTF function to complete the task, whereas a C++ Programmer would include IOSTREAM.H and COUT object to complete the task.
Here both programmers are using respective specific libraries and functions.
It made Microsoft to think, why can’t we have a generic library independent to a language?
Scenario 2:
I need to convert VB code snippet to C++ code snippet. The basic problem that I would face would be Data types. As we know VB language data type would take high memory and range as compared to C++ data types. I mean we don’t have any proportionate measure towards data types that may lead to bugs.
It made Microsoft to think, why can’t we have generic data types independent to a language?
Scenario 3:
Tradition programming languages like C, C++ follows: The source code to be written by programmer, compile the source code to generate a machine dependent object code (ASCII based), and finally run the program. Here, the object or machine code talking about is specific to hardware (processor) and also the Operating system. I mean it may not resist properly in all hardware or software platform. In short it is becoming platform dependent. It leads to develop MSIL code – independent to HW and OS.
It made Microsoft to think, why can’t we have platform independent code instead dependent?
Scenario 4:
Programmers need to face IDE problems a lot in the past. Consider a Java programmer use the core
java AWT library and develop window application. To develop web application he needs to install all
the Tomcat, JSDK. To develop Mobile application he needs to install J2ME. Hence, based on application he needs to install and adapt to the IDE. It’s quite troublesome job.
It made Microsoft to think, why can’t we have Generic IDE?
Finally Microsoft research leads to achieve a framework that would be:
· Language independent
· Platform independent
· Interoperable
· Generic framework
· MSIL Code
· Generic Visual Studio.Net IDE
· Avoid deployment and versioning conflicts (DLL Hell to Assemblies Heaven)
· Guarantee safe execution of code, even if written by unknown semi-trusted third party
· Preserve consistency between objects that are stored and executed locally, objects that are Internet-distributed but are executed locally, and objects that are stored and executed remotely on a server.
· Guarantee safe execution of code, even if written by unknown semi-trusted third party.
What is MS.NET?
According to Microsoft MS.Net is a platform built on open internet protocols & standards with tools and services that meld computing and communication in new ways.
It can also be treated as Microsoft framework that targets a programmer to design, develop and deploy an application of his choice irrespective of console, window, web; mobile etc with an ease IDE.
What is a framework?
Framework refers to a logical collection of rich object oriented classes and interfaces that help us to build simplex to complex applications of any choice. Examples: MS.NET, AJAX.NET, J2EE etc.
All packed Ready to use components.
Microsoft.NET Architecture
1. MS.Net Base Class Libraries (.BCL) or Framework Class Libraries (.FCL)
2. CLR (common Language Runtime)
CTS
a. JIT
b. Assemblies
c. Garbage Collector
d. CLS
e. ASP.Net Security Manager
f. Class Loader
3. Designer Tools (visual studio.NET)
1. MS.NET Base Class Library (.BCL/.FCL)
MS.NET base class library is a logical collection of rich object oriented classes and interfaces that provide support to build simplex to complex application irrespective of an application type. The library provided can be highly reusable and extensible into your managed code. These libraries are well integrated under the common language runtime. Hence, if you are comfort in one .Net language, you can migrate to any of the .NET languages.
All the base class libraries are grouped under the common namespace System. Also the base class for the entire base class library is class Object.
What is a namespace?
Namespace is a logical collection of classes and interfaces with a unique name. The structure of the namespace is like a tree where all the related classes are like leaves.
Advantage of namespace: it helps to organize the library, avoids ambiguity of common classes
The most important namespaces are listed below:
System System.IO System.Security System.NET System.Windows.Forms System.Data.SQLClient System.Drawing System.XML
2. CLR – Common Language Runtime
CLR is the foundation and functional component of .NET framework that manages code at execution time in terms of Memory management, security management, thread management, etc. it enables the code to run on different platforms client or server. It also enforces strict variable types, robustness.
How MS.NET works?
The code written in these languages is compiled with their respective language compliers to give a common intermediate language called MSIL (Microsoft Intermediate Language) and Metadata.
This files generated are called as PE (Portable Executable).
CLR utilizes JIT and converts the MSIL Code back to Native Code.
What is MSIL Code?
MSIL is an intermediate instruction set which is hardware (processor) and software (operating system) independent. The source code when compiled gives MSIL which is an input to the operating system and with the help of CLR is again converted into native code which is processor specific.
What is Meta Data?
Data refers to collection of raw facts and figures. Also an organized data refers to information.
Example: For a student database with ID and Name fields: 19, PRATI is an instance of data
whereas integer ID, string Name represents Meta data.
Hence, information about a data is actually Metadata.
Metadata is binary information describing your program that is stored either in a common language runtime portable executable (PE) file or in memory. When you compile your code into a PE file, metadata is inserted into one portion of the file, while your code is converted to Microsoft intermediate language (MSIL) and inserted into another portion of the file. Every type and member defined and referenced in a module or assembly is described within metadata. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on.
Metadata stores the following information:
a) Description of the assembly.
· Identity (name, version, culture, public key).
· The types that are exported.
· Other assemblies that this assembly depends on.
· Security permissions needed to run.
b) Description of types.
· Name, visibility, base class, and interfaces implemented.
· Members (methods, fields, properties, events, nested types).
c) Attributes.
· Additional descriptive elements that modify types and members
Note: MS.NET framework is generic whereas CLR remains specific to Operating System. I mean Windows CLR will be different from Linux operating system CLR.
IS MS.NET Platform Independent? Yes and NO (Why?)
(Its partial platform independent)
Yes – MS.Net is platform independent as it allows CLR to be installed on all operating systems of windows – Previous and latest. The latest windows operating system comes inbuilt with MS.Net framework. For old operating systems of windows it provides Service Packs to be installed.
Also Microsoft implemented C#.NET in Linux operating system as MONO.NET.
NO – MS.Net is not platform independent as it needs, to provide implementation to all the operating systems.
ILASM and ILDASM
Microsoft provides tools like ILASM and ILDASM to manage .IL programs. I mean MSIL code can be rewritten to source code provided you have DOTFUSCATOR license on your company name.
.assembly MyAssembly {}
.class MyApp { .method static void Main() { .entrypoint ldstr Hello, IL!" call void System.Console::WriteLine(class System.Object) ret } }
What is Managed code?
It means that the complete life cycle and execution is managed by the .NET Common Language Runtime (CLR). The .NET CLR manages the memory on behalf of the managed code, performs garbage collection on the managed heap, perform assembly validation and assembly (component) resolution on behalf of the program. The CLR also maintains the security constraints applied to the managed code.
The managed execution process includes the following steps:
a) Choosing a Compiler: To obtain the benefits provided by the common language runtime, you must use one or more language compilers that target the runtime.
b) Compiling your code to MSIL: Compiling translates your source code into MSIL and generates the required metadata.
c) Compiling MSIL to native code: At execution time, a just-in-time (JIT) compiler translates the MSIL into native code. During this compilation, code must pass a verification process that examines the MSIL and metadata to find out whether the code can be determined to be type safe.
d) Running code: The common language runtime provides the infrastructure that enables execution to take place as well as a variety of services that can be used during execution.
CLR Component – CTS - Common Type System
As I already discussed above, if I need to convert one Language code to another. The major problem would be failing to manage specific data types in terms of memory and range factors. To overcome
this problem they came with Interoperable feature in MS.NET – CTS.
It is a specification where different data types are defined. This .net data type collection is used by
the language compilers to map the language data types to data types defined in CTS.
This ensures the interoperability at runtime as the code written in one language when invoked from another language would not be misinterpret the data because the calling language data types would map the same CTS data types to which the called language data types are mapped.
All types derive from the System. Object base type. They are categorized under value and reference.
CTS provide a framework for cross-language integration and address a number of issues like Inconsistent object models, Limited code reuse. CTS define how types are declared, used, and managed in the runtime, and are also an important part of the runtime's support for cross-language integration.
CLR Component - JIT – Just in time compiler
JIT compiler compiles the managed or MSIL code into native code. JIT compiles only the required code for execution i.e. as the code is being visited for execution and also the compiled code is cached so that if the block of code is called again the same cached copy is directly executed. Advantage of managed code being compiled in small required fractions is processor time.
Pre JIT was planned in the initial draft of .NET but was never supported instead Microsoft provided the utility program called NGen.exe (Native Generator) here the complete MSIL code is compiled to native code for that machine and is stored in GAC (Global Assembly Cache) The advantage being the first time execution is also very fast because its already in precompiled form, but the output of the NGen is not portable and is always machine dependent.
Finally two types of JIT compilers:
Standard JIT (For desktops)
ECONO JIT (For handhelds) = Standard JIT – CACHING
CLR Component – CLS – Common Language Specification
The CLS is a set of constructs and constraints that serves as a guide for library writers and compiler writers. It allows libraries to be fully usable from any language supporting the CLS, and for those languages to integrate with each other. The CLS is a subset of the CTS.
CLR Component – Garbage Collector
Tradition C, C++ programmers need to manage themselves the objects using the calloc,malloc, delete functions. If they are unable to manage objects on heap properly it may lead to Memory Leakage.
In MS.Net the memory de-allocation in .Net is handled by Garbage Collector. It gets activated when the heap is full and there is a need for release of memory.
Garbage Collector a background thread running within the application / CLR and is responsible for destroying all the unreferenced objects (objects which are no longer in use). When garbage collector is initiated all other threads running within the application are temporarily suspended and hence the sooner the garbage collector finishes its job the better would be the performance of the application.
To optimize the work of garbage collector Microsoft has divided the heap memory into three equal parts called Generations: GEN0, GEN1, and GEN2. This is compact garbage collection. New objects are always created in GEN0 and are promoted to other generations based on their lifespan. Long lived objects would be destroyed last as these objects would move from GEN0 to GEN1 and from GEN1 to GEN2.
CLR Component – Class Loader
It is a sub component in CLR and is responsible for loading classes and other types as and when needed. It also loads the PE if it’s not already loaded.
CLR Component – Assemblies
what is an assembly?
An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or as accessible by code outside that unit.
Assemblies are self-describing by means of their manifest, which is an integral part of every assembly. The manifest:
- Establishes the assembly identity (in the form of a text name), version, culture, and digital signature (if the assembly is to be shared across applications).
- Defines what files (by name and file hash) make up the assembly implementation.
- Specifies the types and resources that make up the assembly, including which are exported from the assembly.
- Itemizes the compile-time dependencies on other assemblies.
- Specifies the set of permissions required for the assembly to run properly.
This information is used at run time to resolve references, enforce version binding policy, and validate the integrity of loaded assemblies. The runtime can determine and locate the assembly for any running object, since every type is loaded in the context of an assembly. Assemblies are also the unit at which code access security permissions are applied. The identity evidence for each assembly is considered separately when determining what permissions to grant the code it contains.
The self-describing nature of assemblies also helps makes zero-impact install and XCOPY deployment feasible.
What are private assemblies and shared assemblies?
A private assembly is used only by a single application, and is stored in that application's install directory (or a subdirectory therein). A shared assembly is one that can be referenced by more than one application. In order to share an assembly, the assembly must be explicitly built for this purpose by giving it a cryptographically strong name (referred to as a strong name). By contrast, a private assembly name need only be unique within the application that uses it.
By making a distinction between private and shared assemblies, we introduce the notion of sharing as an explicit decision. Simply by deploying private assemblies to an application directory, you can guarantee that that application will run only with the bits it was built and deployed with. References to private assemblies will only be resolved locally to the private application directory.
· The classes that ship with the .NET Framework are all built as shared assemblies.
· Managed types you build today can be made accessible from COM.
· Using platform invoke, .NET Framework programs can access native code libraries by means of static DLL entry points.
3. Designer Tools
Microsoft provides a generic IDE – Integrated development Environment to develop an application of type console, window, mobile etc. Hence it’s a common gateway to a design, develop and deploy an application.
Designer tool Name: Microsoft Visual Studio.NET 2002 Framework 1.0
Microsoft Visual Studio.NET 2003 Framework 1.1
Microsoft Visual Studio.NET 2005 Framework 2.0
Microsoft Visual Studio.NET 2005 Framework 3.0
Microsoft Visual Studio.NET 2008 Framework 3.5
Microsoft Visual Studio.NET 2010 Framework 4.0
it’s a Multi Lingual and Multi Application IDE.
MS.NET framework 4.0 - Diagram
MS.NET framework Comparison chart – Diagram
Advantages of MS.NET
· Object oriented programming
· Good Design
· Language Independence (Interoperable)
· Code Sharing with Assemblies
· Efficient Data Access
· Better support for dynamic web pages
· Code Sharing
· Support for web services
Summary
we understood Microsoft.Net framework in terms of need, importance, architecture and designer tools. We identified the major components of framework like CLS, CTS, JIT and Assemblies.
We explored platform and language independence features and the advantages of .NET.