Vous êtes sur la page 1sur 24

Overview of Microsoft .

NET Platform
 Introduction to the .NET Platform

 Languages in the .NET Framework

 Types of Application Architecture

 Overview of the .NET Framework

 The .NET Framework Components

 Advantages & Benefits of the .NET Framework

 Common Language Runtime - CLR

 Common Language Specification - CLS

 Common Type System

 Namespace

 Assembly

● Definition

● Assembly Functions

● Types of Assembly

● Shared Assembly

● Global Assembly Cache

● Satellite Assembly

● Reference

● Side by Side Execution

● DLL Hell
Introduction to the .NET Platform

The .Net Platform is a set of technologies designed to transform the Internet into a full-scale distributed
computing platform.

Core Technologies :

● The .NET Framework

● The .NET Enterprise Servers

● Visual Studio .NET

The .NET Framework

The .NET Framework is an integral Windows component that supports building and running the next
generation of applications and XML Web services.

The .NET Framework has two main components:

● Common language runtime

● .NET Framework class library.

.NET Enterprise Servers

Microsoft BizTalk Server :


Provides enterprise application integration, business to business integration.

Microsoft Mobile Information Server :


Provides secure communications and data exchange with mobile devices.

Portal Server :
To create corporate web portals.
Visual Studio.NET

Visual Studio.NET provides an development environment for building applications on the .NET
Framework.

The Visual Studio .NET Integrated Development Environment (IDE) provides you with a common
interface for developing various kinds of projects for the .NET Framework.

In Visual Studio .NET, an application can be made up of one or more items, such as files and folders. To
organize these items efficiently, Visual Studio .NET has provided two types of containers:

● Projects

● Solutions

Visual Studio.NET IDE

The various components of the Visual Studio .NET IDE are:

➢ The Start Page

➢ Windows Forms Designer

➢ The Solution Explorer Window

➢ The Properties Window

➢ Toolbox

➢ The Output Window

➢ The Task List Window

➢ The Server Explorer Window

➢ The Dynamic Help Window

Navigational Features in Visual Studio.NET IDE

● The Class View Window


● The Code and Text Editor Window

The Visual Studio .NET IDE also provides three navigational features:

● Docking

● Tabbed navigation

● Auto hide
Languages in the .NET Framework
● C# – Designed for .NET

New component-oriented language

● Managed Extensions to C++

Enhanced to provide more power and control

● Visual Basic .NET

New version of Visual Basic with substantial language innovations

● JScript .NET

New version of JScript that provides improved performance and productivity

● J# .NET

.NET Java-language support enabling new development and Java migration

● Third-party Languages

C# - Language

C# is a new language having a complete access to the same rich class libraries that are used by seasoned tools

such as Visual Basic and Visual C++.

C# is the language of .NET. Most of the .NET Framework is written using C# language. While we can

program .NET in many languages, C# is specifically designed to work well with .NET and to support

component-based programming.

C# is a great language to program in as it offers several key benefits for programmers.

Features of C#

● Consistency

● Modernity

● Simplicity

● Garbage Collection

● Object-Orientation

● Type-safety

● Scalability

● Version support

● Flexibility
VB.NET

Visual Basic .NET is one of the languages that are directed towards meeting the objectives of the .NET
initiative of creating distributed applications.

Visual Basic .NET is a powerful object-oriented language that provides features such as abstraction,
encapsulation, inheritance, and polymorphism.

Features of VB.NET
● Inheritance

● Constructors and Destructor's

● Overloading

● Overriding

● Structured exception handling

● Multithreading

Jscript

Visual Basic .NET and Jscript.NET languages have very similar performance characteristics : Neither of

them is noticeably faster than the other in the general case.

Jscript.NET is a major evolution of Jscript and the scripting platform, providing a rich, robust language

that builds on the existing script language while providing a flexible way to start building bigger scripts. The key

to all these enhancements in Jscript and Visual Basic is the .NET framework on which they are built.

Web Support

The Internet is quickly evolving from today’s Websites that just deliver UI Pages to browsers to the next

generation of programmable Websites that directly link organizations, applications, services and devices with one

another.

These programmable Websites become more than passively accessed sites they become reusable, intelligent

Web Services. Websites can make information available through Web Services that you can consume on your own

application!
ASP.NET

Active Server Pages (ASP) is the server-side technology for creating dynamic Web pages. The client’s
browser interpreted the HTML tags and displayed the output on the browser screen.

ASP.NET is a server-side Web technology that can be used to develop dynamic and scalable Web
applications. These applications can connect to databases, interact with users and provide asynchronous services.
It is used on a server to build powerful Web Applications. ASP.NET offers several important advantages over
previous Web development models.
Features of ASP.NET

Some of the key features of ASP .NET are as follows:

● Enhanced Performance

● World-class Tool Support.

● Power and Flexibility

● Simplicity

● Manageability

● Scalability and Availability

● Customizability and Extensibility

● Security

● ASP.NET currently offers built-in support for three languages,

C#, Visual Basic, and JScript


Types of Application Architectures

Applications may vary from single-tier desktop applications (applications that follow the single-tier

architecture) to multi-tier applications (applications that follow the two-,three-, or n-tier architecture).

Single-tier architecture

A single executable file handles all functions relating to the user, business, and data service layers.

Two-tier architecture

Divides an application into the following two components:

● Client

● Server

Three-tier architecture

All the three service layers reside separately, either on the same machine or on different machines.

n-tier architecture

Uses business objects for handling business rules and data access.

Has multiple servers handling business services.


Overview of the .NET Framework

The .NET Framework is an integral Windows component that supports building and running the next
generation of applications and XML Web services.

The .NET Framework has two main components:

● Common language runtime

● .NET Framework class library

Common Language Runtime

It actually runs the code manages so many things for example code execution, garbage collection, memory
allocation, thread management etc.

.NET Framework Class Library

It contains .NET libraries, which are collection of namespaces and classes. The classes and namespaces are

kept in a systematic way and can be used in making any application, code reusability etc.

The root namespace of .NET framework is System; with this namespace many namespaces like web

(system. web), data (system. data), windows (system. windows) are generated which can be further have their

namespaces.
Benefits of the .NET Framework

● Based on Web standards and practices

● Designed using unified application models

● Easy for developers to use

● Extensible classes

Advantages of .NET Framework

● Consistent Programming Model

● Multi-platform applications

● Multi-language integration

● Automatic resource management

● Ease of deployment

.NET Framework Components

● Common Language Runtime

● .NET Framework Class Library

● ADO.NET: Data and XML

● Web Forms and XML Web Services

● User Interface for Windows


Overview of Common Language Runtime

CLR is the Common Language Runtime and it forms the heart of the .NET Framework.

All languages have runtime and its responsibility of the runtime to take care of code execution of the
program. For (Eg) .NET has CLR, Java has Java has JVM

Responsibilities of CLR :-

● Garbage Collection

● Code Access Security

● Code Verification

● Intermediate Language to Native Translators

Garbage Collection

CLR automatically manages memory thus eliminating memory leaks.

When objects are not referred GC automatically releases those memories thus by providing efficient
memory management.

It forces Garbage Collector to run “System.GC.Collect()”


Code Access Security

It grants rights to program depending on the security configuration of the machine.

For (Eg.) Program has rights to edit or create a new file but the security configuration of machine does not
allow the program to delete a file.

It can be defined using “caspol -lg”

It revolves around two concepts code groups and named permission set. Each .net assembly is a member of
particular code group and each group is granted the permission specified in the named permission set.

Code Verification

This ensures proper code execution and type safety while the code runs.

It prevents the source code to perform illegal operation such as accessing invalid memory locations etc.

IL to Native Translators

CLR uses JIT and compiles the IL code to machine code, and then executes.

CLR also determines depending on platform what is optimized way of running the IL code.

Features of Common Language Runtime

Class Loader
Manages metadata in addition to the loading and layout of classes.

MSIL to Native Compiler

Converts MSIL to Native code

Code Manager

Manages the code execution

Garbage Collector

Provides automatic life management of your objects

Security Engine

Provides evidence based security that is based on the origin of code and the use

Debug Engine
Allows to debug the application and trace the execution of code.

Type Checker

Will not allow unsafe casts or uninitialized variables. MSIL can be verified to guarantee Type Safety.

Exception Manager

Provides the structured exceptional handling


Thread Support

Provides classes and interfaces that enable multi threaded programming

COM Marshaller
Provides marshalling to and from COM

.NET Framework class library support

Integrates code with run time that supports .NET Framework Class Library.

Managed Code & Unmanaged Code

The code runs under the environment of CLR is called “Managed Code”.

But if you are using third party software VB 6 or VC++ component they are “Unmanaged code” as .NET
runtime (CLR) does not have access control over the source code execution of the language.

Overview of Common Type System

Defines how types are declared, used and managed in the runtime and is also an important part of the
runtime support for cross language integration.

CTS supports both value and reference types

Comparing Value and Reference Types

Value Types

● Directly contain their data

● Each has its own copy of data

● Operations on one cannot affect another

● Stored in Stack

Reference Types

● Store references to their data (known as objects)

● Two reference variables can reference same object

● Operations on one can affect another

● Stored in heap

Comparing Built-in and User-Defined Value Types

Examples of Built in Value Types :- Int, Float

Examples of User Defined Value Types :- Enum, Struct


Overview of Common Language Specification

CLS is a subset of CTS which all .NET languages expected to support.

The idea is that any program which uses CLS complaint types can inter operate with any .NET
program written in any .NET languages.

Intermediate Language

Intermediate Language is also known as MSIL or CIL

All the .NET source code is compiled to IL. This IL is then converted into machine code at the point where the
software is installed or at run time by JIT compiler.

How to view the Assembly ? / What is ILDASM ?

● ILDASM basically converts the whole EXE or DLL to IL code.

● To run ILDASM -> C:\Program Files\Microsoft Visual Studio.NET 2005\SDK\v2.0\Bin

● If you run IDASM.EXE from the path you will be popped with the IDASM exe program. Click on file and
browse to the respective directory for the DLL whose assembly you want to view.

● After you select the DLL you will be popped with a tree view details of the DLL is shown in ILDASM view.

● On double clicking on manifest you will be able to view the details of assembly, internal IL code in Manifest
view

Intermediate Language Disassembler View


Manifest View

Just In Time Compiler - JIT

JIT compiler is a part of .NET run time execution environment.

It converts IL to Native Code.

There are three types of JIT Compilers :-

Pre JIT

It compiles complete source code into native code in a single compilation cycle. This is done at the time of
deployment of the application.

Econo JIT

It compiles only those methods that called at runtime. However, these compiled methods are removed when
they are not required.

Normal JIT

It compiles only those methods are called at runtime. These methods are compiled the first time they are
called, and then they are stored in cache. When the same methods are called again, the compiled code from cache
is used for execution.
Namespace

Namespace has two basic functionality.

Namespace logically groups of types.

Eg. System.Web.UI logically groups our UI related features.

In our object oriented world, many times it is possible that programmers will use the same class name. By
qualifying Namespace with Class Name this collisions is able to be removed.

The difference between Namespace and Assembly

● Assembly is a physical grouping of logical units.

● Namespace logically groups classes.

● Namespace can span multiple assembly.

Assembly

Assembly Definition

● Assemblies are the fundamental building block of .NET framework.

● They contain the type and resources that are useful to make an application.

● Assembly enables code reuse, version control, security and deployment.

● An assembly can have four parts: Manifest, Type Metadata, MSIL and Resource file.

Assembly Functions

● An assembly performs the following functions:

● It contains code that the common language runtime executes. Microsoft intermediate language (MSIL) code

in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest. Note

that each assembly can have only one entry point (that is, DllMain, WinMain, or Main).

● It forms a security boundary

An assembly is the unit at which permissions are requested and granted.


● It forms a type boundary

Every type's identity includes the name of the assembly in which it resides. A type called MyType loaded in the

scope of one assembly is not the same as a type called MyType loaded in the scope of another assembly.

● It forms a reference scope boundary

The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource

requests. It specifies the types and resources that are exposed outside the assembly. The manifest also enumerates

other assemblies on which it depends.

● It forms a version boundary

The assembly is the smallest versionable unit in the common language runtime; all types and resources in the

same assembly are versioned as a unit. The assembly's manifest describes the version dependencies you specify for

any dependent assemblies.

● It is the unit at which side-by-side execution is supported.

● It forms a deployment unit

When an application starts, only the assemblies that the application initially calls must be present. Other

assemblies, such as localization resources or assemblies containing utility classes, can be retrieved on demand. This

allows applications to be kept simple and thin when first downloaded.

● Assemblies can be either static or dynamic :-

Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the

assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files.

You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and

are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.
Assembly Types

Private

A private assembly is normally used by a single application, and is stored in the application's directory, or a

sub-directory beneath.

Public / Shared

A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies

maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will

find useful, e.g. the .NET framework classes.

The runtime enforces versioning constraints only on shared assemblies, not on private assemblies.

How to create Shared Assembly

● Create your EXE / DLL source code

● Generate unique assembly using SN utility

● Sign your DLL/EXE with private key by modifying assembly information file.

● Compile your DLL/EXE

● Place the resultant DLL/EXE in GAC using AL utility

Global Assembly Cache - GAC

● Each computer where the common language runtime is installed has a machine-wide code cache called the

global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by

several applications on the computer.

● You should share assemblies by installing them into the global assembly cache only when you need to.
Steps :-

● Create a strong name using sn.exe tool eg: sn -k keyPair.snk

● With in AssemblyInfo.cs add the generated file name

eg: [assembly: AssemblyKeyFile("abc.snk")]

● Recompile project, then install it to GAC by either drag & drop it to assembly folder

(C:\WINDOWS\assembly OR C:\WINNT\assembly) (shfusion.dll tool)

(or)

gacutil -i abc.dll

Satellite Assembly

When you write a multilingual or multi-cultural application in .NET, and want to distribute the core

application separately from the localized modules, the localized assemblies that modify the core application are

called satellite assemblies.

Assembly Reference

Partial Assembly Reference :

We can dynamically reference an assembly by providing only partial information such as specifying only the
assembly name.

When you specify a partial assembly reference, the runtime looks only in the application.

Full Assembly Reference :

A full assembly reference includes the assembly's text name, version, culture and public key token. It is

required if you reference any assembly that is part of CLR or any assembly located in GAC.

Side by Side Execution

Is the ability to run multiple versions of an application or component on the same computer. You can have
multiple versions of CLR and multiple versions of applications and components that use a versions of CLR on the
same computer at the same time.

Since the versioning is applicable to the shared assemblies and not to the private assemblies.

Two applications one using private assembly and one using shared assembly cannot be stated as side-by-side
execution.
DLL Hell

Prior to the .NET Framework, application shared DLL files. If one application needed a new version of the

DLL, it would update DLL during the installation. As a result of this update, the other programs using DLL may

no longer function properly. These DLL versioning issues are commonly referred to as DLL Hell.

In .NET environment if the application requires a particular version of a DLL, you can specify that version

in the application. The runtime ensures that correct version of the DLL is available for application. Thus runtime

allows multiple versions of DLL to exist and run at the same time.

Assembly versioning

All versioning of assemblies that uses CLR is done at the assembly level. The assembly version information is
stored in manifest.

Each assembly has two distinct ways of expressing version information.

The assembly version number, which together with the assembly name and culture information is part of the
assembly's identity.

Each assembly has a version number as part of its identity. As such, two assemblies that differ by the version
number are considered by the run time to be completely different assemblies.

The version number is physically represented as four part string with the following format:

<major version>. <minor version>. <build version>.<revision> For (Eg) 1.5.1254.0

Major or Minor

Changes to the major or minor portion of the version number indicate an incompatible change. Under this

convention then, version 2.0.0.0 would be considered incompatible with version 1.0.0.0.

Examples of an incompatible change would be a change to the types of some method parameters or the

removal of a type or method altogether. Build. The Build number is typically used to distinguish between daily

builds or smaller compatible releases. Revision. Changes to the revision number are typically reserved for an

incremental build needed to fix a particular bug. You'll sometimes hear this referred to as the "emergency bug

fix" number in that the revision is what is often changed when a fix to a specific bug is shipped to a customer.
Assembly Manifest

Assembly Metadata is stored in Manifest.

Manifest contains all the metadata needed to do the following things:

- Version of Assembly

- Security Identity

- Scope of Assembly

- Resolve reference to resources and classes

– Stored in either a PE file with MSIL code or standalone PE file that contains only assembly manifest
information.

Diff Between Manifest & Metadata :-

Manifest describes the assembly itself. Assembly name, version number, culture information. Strong name, list

of all files, type reference and reference assembly.

While the Metadata describes the contents within the assembly. Like classes, interfaces, namespaces, base class,

scope, properties and their parameters etc.

Strong Name

● A name that consists of an assembly's identity—its simple text name, version number, and culture

information (if provided)—strengthened by a public key and a digital signature generated over the

assembly. The advantage is globally unique assembly and security.

To generate the strong name :-

● Go to visual studio command prompt

● In command prompt type sn.exe -k “c:\test.snk”

● After generation of the file you can view the SNK file in a simple notepad.

● After the SNK file is generated its time to sign the project with this SNK file.

● Click on Project properties and browse the SNK file to the respective folder and compile the project.
Serialization

Process of converting an object into a stream of bytes is called Serialization.

Process of creating an object from stream of bytes is called Deserialization.

Both are used to transport objects (during remoting) or to persist objects(file/database).

Types of serialization : Binary and XML

Binary Serialization :- Preserves the fidelity, which is useful for preserving the state of an object between
different invocations of an application.

XML Serialization :- Serializes only public properties and fields and does not preserve fidelity. This is useful
when you want to provide or consume data without restricting the application that uses the data.

Reflection

● All .NET compilers produce metadata about the types defined in modules they produce. The metadata is

packed along with the module and can be accessed by a mechanism called Reflection.

● System.Reflection namespace contains classes that can be used to interrogate the types of module / assembly.

App Domain

● The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes

provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn't scale

well.

● The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in

the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each

other's memory.

● Objects in different application domains communicate either by transporting copies of objects across

application domain boundaries, or by using a proxy to exchange messages.


Marshall by Ref & Marshall by Value

● MarshalByRefObject is the base class for objects that communicate across application domain boundaries

by exchanging messages using a proxy.

● Objects that do not inherit from MarshalByRefObject are implicitly Marshal By Value. When a

remote application references a marshal by value object, a copy of the object is passed across application

domain boundaries.

Delay Signing

During development process, strong name keys to be exposed to developer which is not good practice from
security aspect, In such situations you can assign the key later on and during development you can use delay
signing.

Delay Signing Steps :

● Creating strong name

[assembly:AssemblyKeyFileAttribute(“mykey.snk”)]

● Setting Delay Sign Attribute to true

[assembly:AssemblyDelaySignAttribute(true)]

The compiler inserts the public key into the assembly manifest and reserves space in the PE file for the full

strong name signature. The real public key must be stored while the assembly is built so that other assemblies that

reference this assembly can obtain the key to store in their own assembly's reference.

Sn-Vr myAssembly.dll

The assembly does not have strong name signature, the verification of that signature must be turned off, you

can use -Vr option with the strong name tool.

Sn-R myAssembly.dll sgKey.snk

Just before shipping, submit the assembly with -R option with the Strong Name tool. The above code signs an

assembly myAssembly.dll with a strong name using the sgKey.snk key pair.
Code DOM

● Object model which represents actually a source code.

● Designed to be language independent.

● Once Code Dom is created, we can generate the source code in any .NET complaint languages.

Native Image Generator (Ngen.exe)

● The utility allows you o run the JIT compiler on your assembly's MSIL and generate native machine code

which is cached to disk.

● After the image is created .NET runtime will use the image to run the code from cache rather than from the

hard disk.

● Running Ngen.exe on an assembly potentially allows the assembly to load and execute faster, because it

restores code and data structures from the native image cache rather than generating them dynamically.

● To un-install an assembly and its dependencies from the native image cache by running the following

command. ngen.exe uninstall<assemblyname>

To run Ngen.exe / Install

● In .NET 2.0 there is a service(.NET Optimization Service) which can precompile managed assemblies in the

background. You can schedule your assemblies to be precompiled asynchronously by queuing them up with

NGEN service, use the following command line.

ngen.exe install<assemblyname>/queue<priority>

● Assemblies which are critical to your application's start up time should be either be precompiled

synchronously or asynchronously with priority 1. Priority 1 & 2 are compiled aggressively, while priority 3

will be pre-compiled during idle time.

● Synchronously pre-compiling your critical assemblies guarantees that native images will be available prior to

the first time, when the end user launches the application but increases the time taken to run your

application's set up.

Vous aimerez peut-être aussi