+ All Categories
Home > Documents > Introduction.NET Framework. .NET Framework.NET Framework is a complete environment that allows...

Introduction.NET Framework. .NET Framework.NET Framework is a complete environment that allows...

Date post: 29-Dec-2015
Category:
Upload: denis-hawkins
View: 230 times
Download: 1 times
Share this document with a friend
Popular Tags:
27
Introduction .NET Framework
Transcript

Introduction .NET Framework

.NET Framework.NET Framework is a complete environment that allows developers to develop, execute,

and deploy the following applications:

• Console applications• Windows Forms applications• Windows Presentation Foundation (WPF) applications• Web applications (ASP.NET applications)• Web services• Windows services• Service-oriented applications using Windows Communication Foundation (WCF)• Workflow-enabled applications using Windows Workflow Foundation (WF)

.NET Framework also enables a developer to create sharable components to be used in distributed computing architecture.

.NET Framework supports the object-oriented programming model for multiple languages, such as Visual Basic, Visual C#, and Visual C++.

.NET Framework supports multiple programming languages in a manner that allows language interoperability.

Features / Advantages• Interoperability

– .Net framework provides the way to operate .Net application outside the .Net environment. Access to COM components is facilitated to .Net developers in the SRIS and System Enterprise Services namespace. By this facility this platform is increasing the communication between new applications and the old applications.

• Common Language Runtime engine

– Common Language Runtime (CLR) is the virtual machine component of the .NET framework. All .NET programs execute under the supervision of the CLR, and it provides memory management, security, and exception handling.

• Language independence– .NET Framework introduces a Common Type System, or CTS. The CTS

specification defines all possible data types and programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports the exchange of instances of types between programs written in any of the .NET languages.

Features / Advantages• 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 which encapsulate a number of common functions, including file reading and writing, graphic rendering, database interaction and XML document manipulation.

• Simplified deployment– The .NET framework includes design features and tools that help manage the

installation of computer software to ensure that it does not interfere with previously installed software, and that it conforms to security requirements.

• Security– The design is meant to address some of the vulnerabilities, such as buffer overflows,

that have been exploited by malicious software. Additionally, .NET provides a common security model for all applications.

• Portability– .NET framework permits it to be platform agnostic, and therefore it is compatible with

different platforms. This feature of Microsoft .NET framework also makes a way for third parties to develop compatible implementations of this framework and its languages on platforms other than Microsoft.

• CLI is an open specification developed by Microsoft and standardized by ISO and ECMA.

• CLI describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET.

• The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

• CLI specification describes the following four aspects: – Common Type System (CTS)

– Metadata

– Common Language Specification (CLS)

– Virtual Execution System (VES)  

Common Language Infrastructure  (CLI)

Common Language Infrastructure  (CLI)

Common Intermediate Language   (CIL)

• (CIL) Common Intermediate Language is also known as (MSIL) Microsoft Intermediate Language or IL ( Intermediate Language).

• CIL is the lowest-level human-readable programming language defined by the Common Language Infrastructure (CLI) specification.

• All .NET source code is compiled to CIL. Then CIL will be converted to native code and code will be executed at run-time by a Just-In- Time (JIT) compiler.

 

Common Language Runtime(CLR)

• Common Language Runtime (CLR) is the virtual machine and core component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs.

• CLR is a common runtime environment for .NET native code which is converted by MSIL or IL (Intermediate Language) from bytecode that is complied with .NET compilers of respective language in .NET Framework.

• CLR performs various tasks to manage the execution process of .NET applications.

• The responsibilities of CLR are listed as follows:Automatic memory managementGarbage CollectionCode Access SecurityCode verificationJIT compilation of .NET code

Common Language Runtime(CLR)

Common Type System (CTS)

• The Common Type System (CTS) defines how types are declared, used and managed in the runtime, and is also an important part of the runtime(CLR)'s support for cross-language integration.

• The common type system performs the following functions:– Establishes a framework that helps enable cross-language integration,

type safety, and high-performance code execution.

– Provides an object-oriented model that supports the complete implementation of many programming languages.

– Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

– Provides a library that contains the primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in application development.

Common Type System (CTS)

• All types in the .NET Framework are either value types or reference types:

– Value types are data types whose objects are represented by the object's actual value. If an instance of a value type is assigned to a variable, that variable is given a fresh copy of the value.

– Reference types are data types whose objects are represented by a reference (similar to a pointer) to the object's actual value. If a reference type is assigned to a variable, that variable references (points to) the original value. No copy is made.

Common Language Specification(CLS)

• It is a sub set of CTS and it specifies a set of rules that needs to be adhered or satisfied by all language compilers targeting CLR. It helps in cross language inheritance and cross language debugging.

Common language specification Rules:

1. Representation of text strings 

2. Internal representation of enumerations 

3. Definition of static members and this is a subset of the CTS which all .NET languages are expected to support.

4. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.

Framework Class Library(FCL)

• The .NET Framework class library is a library of classes, interfaces, and value types that provide access to system functionality. It is the foundation on which .NET Framework applications, components, and controls are built. 

• FCL contains thousands of classes to provide the access to Windows API and common functions like String Manipulation, Common Data Structures, IO, Streams, Threads, Security, Network Programming, Windows Programming, Web Programming, Data Access, etc.

• It is simply the largest standard library ever shipped with any development environment or programming language. The best part of this library is they follow extremely efficient OO design (design patterns) making their access and use very simple and predictable.

namespace

• The namespace  is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.

• Namespace is a collection of types.

• A namespace can contain one or more of the following types:

class, struct, interface, enum and delegate

• A namespace can have one or more sub namespaces defined in it.• Namespace also avoids collision between names of types in a

program.

• By default a program has a namespace called <global namespace>

• using directive to allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:

ex. using System;

namespace• Namespaces are heavily used in C# programming in two ways. First, the .NET Framework uses namespaces to

organize its many classes, as follows: • System is a namespace and Console is a class in that namespace. The using keyword can be used so that the

complete name is not required, as in the following example:• using System;• System.Console.WriteLine("Hello World!"); • Second, declaring your own namespaces can help you control the scope of class and method names in larger

programming projects. Use the namespace keyword to declare a namespace, as in the following example:

Example:

namespace SampleNamespace

{

class SampleClass

{

public void SampleMethod()

{

System.Console.WriteLine( "SampleMethod inside SampleNamespace");

}

}

}

Using SampleNamespace;

Assembly

• Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security.

• An assembly consist of one or more files (dlls , exe’s. html files etc.), and represents a collection of types and resources that are built to work together and form a logical unit of functionality.

• An assembly is completely self-describing. An assembly contains metadata and manifest.

Types of AssemblyThere are the two types of assemblies:

• Private Assembly - Refers to the assembly that is used by a single application. Private assemblies are kept in a local folder in which the client application has been installed.

• Public or Shared Assembly - Refers to the assembly that is allowed to be shared by multiple applications. A shared assembly must reside in Global Assembly Cache (GAC) with a strong name assigned to it.

• For example, imagine that you have created a DLL containing information about your business logic. This DLL can be used by your client application. In order to run the client application, the DLL must be included in the same folder in which the client application has been installed. This makes the assembly private to your application. Now suppose that the DLL needs to be reused in different applications. Therefore, instead of copying the DLL in every client application folder, it can be placed in the global assembly cache using the GAC tool. These assemblies are called shared assemblies.

Metadata• An assembly metadata is binary information which describes the

description of an assembly, such as name, version, culture, public key of an assembly along with the types exported, other assemblies dependent on this assembly, and security permissions needed to run the application.

• In addition, it stores the description of types, such as the name, visibility, base class, interfaces implemented, and members, such as methods, fields, properties, events, attributes and nested types.

• Metadata is stored in binary format. Therefore, metadata of an assembly is sharable among applications that execute on various platforms. It can also be exported to other applications to give information about the services and various features of an application.

Manifest • Assemblies maintain all their information in a special unit called the manifest. Every assembly

has a manifest.

The followings are the contents of an Assembly Manifest:

Execution Model of Assembly

Just-In-Time(JIT)

• JIT compiler translates the MSIL code of an assembly to native code and uses the CPU architecture of the target machine to execute a .NET application.

• It also stores the resulting native code so that it is accessible for subsequent calls.

• If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code.

• JIT compiler also enforces type-safety in the runtime environment of the .NET Framework.

• It checks for the values that are passed to parameters of any method.

• The following are the various types of JIT compilation in .NET:Pre - JITEcono - JITNormal - JIT

Types of JIT• Pre - JIT

– In Pre-JIT compilation, complete source code is converted into native code in a single cycle (i.e. compiles the entire code into native code in one stretch)

– This is done at the time of application deployment.– In .Net it is called "Ngen.exe“

• Econo - JIT– In Econo-JIT compilation, the compiler compiles only those methods that are

called at run time.– After execution of this method the compiled methods are removed from memory.

• Normal - JIT– In Normal-JIT compilation, the compiler compiles only those methods that are

called at run time.– After executing this method, compiled methods are stored in a memory cache.– Now further calls to compiled methods will execute the methods from the

memory cache.

Managed Code & Unmanage Code

• The code which is produced by (vb.net,c#,j#) .net framework language is called as managed code which is under the control of CLR.Garbage collector run automatically in managed code. 

• The code which is produced by third party language is called as unmanaged code, which does not run under the control of CLR.Garbage collector will not run in case of unmanaged code.

CLR Execution Model

VBVBSource Source codecode

CompilerCompiler

C++C++C#C#

CompilerCompilerCompilerCompiler

AssemblyAssemblyIL codeIL code

AssemblyAssemblyIL codeIL code

AssemblyAssemblyIL codeIL code

Operating system servicesOperating system services

Common language runtimeCommon language runtime

JIT compilerJIT compiler

Native codeNative code

ManagedManagedcodecode

UnmanagedUnmanagedcomponentcomponent


Recommended