.NET Framework Overview

48
.NET Framework .NET Framework Overview Overview .NET Framework, CLR, MSIL, .NET Framework, CLR, MSIL, Assemblies, CTS, etc. Assemblies, CTS, etc. Doncho Minkov Doncho Minkov Telerik School Academy Telerik School Academy schoolacademy.telerik schoolacademy.telerik .com .com Technical Trainer Technical Trainer http://www.minkov.it http://www.minkov.it

description

 

Transcript of .NET Framework Overview

Page 1: .NET Framework Overview

.NET Framework .NET Framework OverviewOverview

.NET Framework, CLR, MSIL, .NET Framework, CLR, MSIL, Assemblies, CTS, etc.Assemblies, CTS, etc.

Doncho MinkovDoncho Minkov

Telerik School AcademyTelerik School Academyschoolacademy.telerikschoolacademy.telerik

.com .com

Technical TrainerTechnical Trainerhttp://www.minkov.it http://www.minkov.it

Page 2: .NET Framework Overview

Table of ContentsTable of Contents1.1. What isWhat is .NET.NET??

Microsoft .NET platform Microsoft .NET platform architecturearchitecture

2.2. What isWhat is .NET.NET FrameworkFramework?? .NET Framework Architecture.NET Framework Architecture

3.3. Common Language Runtime (CLR)Common Language Runtime (CLR)

4.4. Managed CodeManaged Code

5.5. Intermediate LanguageIntermediate Language MSILMSIL

6.6. Assemblies and MetadataAssemblies and Metadata

7.7. .NET Applications.NET Applications

Page 3: .NET Framework Overview

Table of ContentsTable of Contents (2) (2)

8.8. Common Language Infrastructure Common Language Infrastructure (CLI)(CLI) and integration of different and integration of different languageslanguages

Common Language Specification Common Language Specification (CLS)(CLS)

Common Type System (CTS)Common Type System (CTS)

9.9. Framework Class LibraryFramework Class Library

10.10. Integrated Development Integrated Development EnvironmentEnvironment Visual StudioVisual Studio

Page 4: .NET Framework Overview

.NET Framework.NET FrameworkMicrosoft's Platform Microsoft's Platform

for Application for Application DevelopmentDevelopment

Page 5: .NET Framework Overview

What is the .NET What is the .NET PlatformPlatform??

The .NET platformThe .NET platform Microsoft's platform for software Microsoft's platform for software

developmentdevelopment Unified technology for development of Unified technology for development of

almost any kind of applicationsalmost any kind of applications GUI / Web / RIA / mobile / server / cloud / GUI / Web / RIA / mobile / server / cloud /

etc.etc.

.NET platform versions.NET platform versions .NET Framework.NET Framework Silverlight / Windows Phone 7Silverlight / Windows Phone 7 .NET Compact Framework.NET Compact Framework

Page 6: .NET Framework Overview

What isWhat is .NET .NET Framework?Framework?

.NET Framework.NET Framework An environment for developing and An environment for developing and

executingexecuting .NET.NET applicationsapplications Unified programming modelUnified programming model, , set of set of

languages, class librarieslanguages, class libraries,, infrastructure, components and tools infrastructure, components and tools for application developmentfor application development

Environment for controlled execution Environment for controlled execution of managed codeof managed code

It is commonly assumed thatIt is commonly assumed that .NET platform == .NET Framework.NET platform == .NET Framework

Page 7: .NET Framework Overview

..NET Framework NET Framework ComponentsComponents

Common Language RuntimeCommon Language Runtime (CLR) (CLR) Environment for controlled executionEnvironment for controlled execution of of

programmed codeprogrammed code – – like a virtual machine like a virtual machine ExecutesExecutes .NET.NET applicationsapplications

Framework Class LibraryFramework Class Library (FCL) (FCL) StandardStandard class library for .NET class library for .NET

developmentdevelopment Delivers basic functionality for Delivers basic functionality for

developingdeveloping:: XML, ADO.NET, LINQ, XML, ADO.NET, LINQ, ASP.NET, WPF, WCF, WWF, Silverlight, ASP.NET, WPF, WCF, WWF, Silverlight, Web services, Windows Forms, Web services, Windows Forms, ......

SDK, compilers and toolsSDK, compilers and tools

Page 8: .NET Framework Overview

.NET Framework .NET Framework ArchitectureArchitecture

The OSThe OS manages themanages the resourcesresources, , the processes and the users of the processes and the users of the machinethe machine

Provides to the applications Provides to the applications some services (threadssome services (threads, , I/O, I/O, GDI+, DirectX, COM, COM+, GDI+, DirectX, COM, COM+, MSMQ, IIS, WMI, …)MSMQ, IIS, WMI, …)

CLR is a separate process in the CLR is a separate process in the OSOS

Operating System (OS)Operating System (OS)

Page 9: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

CLR managesCLR manages the the execution of the.NET codeexecution of the.NET code

Manages the memoryManages the memory, , concurrencyconcurrency, , securitysecurity, ..., ...

.NET Framework .NET Framework Architecture Architecture (2)(2)

CLRCLR

Page 10: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

.NET Framework .NET Framework Architecture Architecture ((33))

Rich object-oriented library Rich object-oriented library with fundamental classeswith fundamental classes

Input-output, collections, Input-output, collections, text processing, text processing, networking,networking, securitysecurity, , multi-multi-threadingthreading, , ……

Page 11: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

.NET Framework .NET Framework Architecture Architecture ((44))

Database accessDatabase access ADO.NET, LINQ, LINQ-to-ADO.NET, LINQ, LINQ-to-

SQL and Entity FrameworkSQL and Entity Framework Strong XML supportStrong XML support

Page 12: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

.NET Framework .NET Framework Architecture Architecture ((55))

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

Windows Communication Windows Communication Foundation (WCF) and Foundation (WCF) and Windows Workflow Windows Workflow Foundation (WWF) for Foundation (WWF) for the SOA worldthe SOA world

Page 13: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

.NET Framework .NET Framework Architecture Architecture ((66))

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

ASP.NETASP.NETWeb Forms, MVC, AJAXWeb Forms, MVC, AJAXMobile Internet ToolkitMobile Internet Toolkit

WindowsWindowsFormsForms WPFWPF SilverlightSilverlight

User interface technologies: User interface technologies: Web based, Windows GUI, WPF, Web based, Windows GUI, WPF, Silverlight, mobile, …Silverlight, mobile, …

Page 14: .NET Framework Overview

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

.NET Framework .NET Framework Architecture Architecture ((77))

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

ASP.NETASP.NETWeb Forms, MVC, AJAXWeb Forms, MVC, AJAXMobile Internet ToolkitMobile Internet Toolkit

WindowsWindowsFormsForms WPFWPF SilverlightSilverlight

C#C# C++C++VB.NETVB.NET J#J# F#F# JScriptJScriptPerlPerlDelphiDelphi ……

Programming language on your Programming language on your flavor!flavor!

Page 15: .NET Framework Overview

.NET Framework 4.0.NET Framework 4.0

15

Page 16: .NET Framework Overview

The FutureThe Future

16

Page 17: .NET Framework Overview

Common Common Language Language

RuntimeRuntime ( (CLRCLR))The Heart of .NET The Heart of .NET FrameworkFramework

Page 18: .NET Framework Overview

Common Language Common Language RuntimeRuntime ( (CLRCLR))

Common Language Common Language RuntimeRuntime ( (CLRCLR))

Managed execution environmentManaged execution environment Controls the execution of Controls the execution of

managedmanaged . .NET programming codeNET programming code Something like virtual machineSomething like virtual machine

Like the Java Virtual Machine (JVM)Like the Java Virtual Machine (JVM) Not an interpreterNot an interpreter

Compilation on-demand is usedCompilation on-demand is used Known as Known as Just In Time (JIT) compilationJust In Time (JIT) compilation

Possible compilation in advance Possible compilation in advance (Ngen)(Ngen)

Page 19: .NET Framework Overview

ResponsibilitiesResponsibilities ofof CLR CLRResponsibilitiesResponsibilities ofof CLR CLR Execution of theExecution of the IL codeIL code andand the JIT the JIT

compilationcompilation

Managing memory and application Managing memory and application resourcesresources

Ensuring type safetyEnsuring type safety

Interaction with the OSInteraction with the OS

Managing securityManaging security

Code access securityCode access security

Role-based securityRole-based security

Page 20: .NET Framework Overview

ResponsibilitiesResponsibilities ofof CLR CLR (2)(2)

Managing exceptionsManaging exceptions Managing concurrency Managing concurrency – – controlling controlling

the parallel execution of the parallel execution of application application threadsthreads

Managing application domains and Managing application domains and their isolationtheir isolation

Interaction with unmanaged codeInteraction with unmanaged code SupportingSupporting debug /debug /

profile of .NET code profile of .NET code

Page 21: .NET Framework Overview

CLR ArchitectureCLR Architecture

Class LoaderClass Loader

IL to NativeIL to NativeJIT CompilerJIT Compiler

CodeCodeManagerManager

GarbageGarbageCollectorCollector

Security EngineSecurity Engine Debug EngineDebug Engine

Type CheckerType Checker Exception ManagerException Manager

Thread SupportThread Support COM MarshalerCOM Marshaler

Base Class Library SupportBase Class Library Support

Page 22: .NET Framework Overview

Managed and Managed and Unmanaged CodeUnmanaged Code

What is the Difference?What is the Difference?

Page 23: .NET Framework Overview

Managed CodeManaged Code CLR executed code is called CLR executed code is called managed codemanaged code Represents programming code in the low Represents programming code in the low

level language level language MSILMSIL (MS Intermediate (MS Intermediate Language)Language)

Contains metadataContains metadata Description of classesDescription of classes, , interfacesinterfaces, ,

propertiesproperties, , fieldsfields, , methodsmethods, , parameters, etc.parameters, etc. ProgramsPrograms, , written in anywritten in any .NET language are.NET language are

Compiled to managed codeCompiled to managed code (MSIL)(MSIL) Packaged as assemblies (Packaged as assemblies (.exe.exe or or ..dlldll files) files)

Page 24: .NET Framework Overview

Managed Code Managed Code (2)(2)Managed Code Managed Code (2)(2)

Object-orientedObject-oriented SecureSecure ReliableReliable

Protected from Protected from irregularirregular use of types use of types ((type-safe)type-safe)

Allows integration between Allows integration between components and data types of components and data types of different programming languagesdifferent programming languages

Portable between different platformsPortable between different platforms Windows, Linux, Max OS X, etc.Windows, Linux, Max OS X, etc.

Page 25: .NET Framework Overview

Unmanaged (Win32) Unmanaged (Win32) CodeCode

No protection of memory and type-No protection of memory and type-safetysafety Reliability problemsReliability problems Safety problemsSafety problems

Doesn’t contain metadataDoesn’t contain metadata Needs additional overhead like (e.g. use Needs additional overhead like (e.g. use

COM)COM) Compiled to machine-dependent codeCompiled to machine-dependent code

Need of different versions for different Need of different versions for different platformsplatforms

Hard to be ported to other platformsHard to be ported to other platforms

Page 26: .NET Framework Overview

Memory ManagementMemory Management CLR manages memory automatically CLR manages memory automatically

Dynamically loadedDynamically loaded objects are stored objects are stored in the in the managed heapmanaged heap

Unusable objects are automatically Unusable objects are automatically cleaned up by the cleaned up by the garbage collectorgarbage collector

Some of the big problems are solvedSome of the big problems are solved Memory leaksMemory leaks Access to freed or unallocated Access to freed or unallocated

memorymemory Objects are accessed through a Objects are accessed through a

referencereference

Page 27: .NET Framework Overview

Intermediate Intermediate Language (MSIL)Language (MSIL)

Page 28: .NET Framework Overview

Intermediate LanguageIntermediate Language ((MSILMSIL, , ILIL,, CIL) CIL)

Low level languageLow level language ( (machine languagemachine language)) for the .NET CLRfor the .NET CLR

Has independent set of CPU instructionsHas independent set of CPU instructions Loading and storing data, calling methods Loading and storing data, calling methods

Arithmetic and logical operationsArithmetic and logical operations Exception handlingException handling Etc.Etc.

MSIL is converted to instructions for the MSIL is converted to instructions for the current physical CPU by the JIT compilercurrent physical CPU by the JIT compiler

Page 29: .NET Framework Overview

SampleSample MSIL ProgramMSIL Program

.method private hidebysig static void Main() cil .method private hidebysig static void Main() cil

managedmanaged

{{

.entrypoint.entrypoint

// Code size 11 (0xb)// Code size 11 (0xb)

.maxstack 8.maxstack 8

ldstr "Hello, world!"ldstr "Hello, world!"

call voidcall void

[mscorlib]System.Console::WriteLine(string)[mscorlib]System.Console::WriteLine(string)

retret

} // end of method HelloWorld::Main} // end of method HelloWorld::Main

Page 30: .NET Framework Overview

Compilation and Compilation and ExecutionExecution

CompilationCompilation

ExecutionExecution

JIT JIT compilecompile

rr

MachinMachine codee code

MSILMSILCodeCode

MetadataMetadataSourcSource codee code

LanguagLanguage e

compilercompiler

AssemAssemblybly

(.EXE (.EXE oror

.DLL .DLL file)file)

When given When given method is method is called for called for the first the first

timetimePre-Pre-compilation compilation during the during the

install install (NGEN)(NGEN)

Page 31: .NET Framework Overview

.NET Applications.NET ApplicationsAssemblies, Metadata and Assemblies, Metadata and

ApplicationsApplications

Page 32: .NET Framework Overview

.NET Assemblies.NET Assemblies .NET assemblies:.NET assemblies:

Self-containing .NET componentsSelf-containing .NET components Stored in .DLL and .EXE filesStored in .DLL and .EXE files

Contain list of classes, types and Contain list of classes, types and resourcesresources

Smallest deployment unit in CLRSmallest deployment unit in CLR Have unique version numberHave unique version number

.NET deployment model.NET deployment model No version conflicts (forget the "DLL No version conflicts (forget the "DLL

hell")hell") Supports side-by-side execution of Supports side-by-side execution of

different versions of the same assemblydifferent versions of the same assembly

Page 33: .NET Framework Overview

Metadata in the Metadata in the AssembliesAssemblies

Metadata in the .NET assembliesMetadata in the .NET assemblies Data about data contained in the Data about data contained in the

assemblyassembly Integral part of the assemblyIntegral part of the assembly Generated by the .NET languages Generated by the .NET languages

compilercompiler Describes all classes, their class Describes all classes, their class

members, versions, resources, etc.members, versions, resources, etc.

Page 34: .NET Framework Overview

Metadata in AssembliesMetadata in Assemblies

Type DescriptionType Description

Assembly DescriptionAssembly Description

Classes, interfaces, inner types, base classes, implemented interfaces, member fields, properties, methods, method parameters, return value,attributes, etc.

Dependencies on other assembliesDependencies on other assembliesSecuritySecurity permissions permissionsExported typesExported types

Dependencies on other assembliesDependencies on other assembliesSecuritySecurity permissions permissionsExported typesExported types

[digital[digitalsignature]signature][digital[digitalsignature]signature]

NameNameVersionVersionLocalizationLocalization

NameNameVersionVersionLocalizationLocalization

Page 35: .NET Framework Overview

..NETNET ApplicationsApplications Configurable executable .NET unitsConfigurable executable .NET units Consist of one or more assembliesConsist of one or more assemblies Installed by "copy / paste"Installed by "copy / paste"

No complex registration of componentsNo complex registration of components Different applications use different Different applications use different

versions of common assembliesversions of common assemblies No conflicts due to their "strong name"No conflicts due to their "strong name"

Easy installationEasy installation, , un-installation and un-installation and updateupdate

Page 36: .NET Framework Overview

Common Type System Common Type System (CTS)(CTS)

CTS defines the CLRCTS defines the CLR supported supported types of data and the operations types of data and the operations over themover them

Ensures data level compatibility Ensures data level compatibility between different .NETbetween different .NET languageslanguages E.g. E.g. stringstring in in C#C# is the same likeis the same like StringString in in VB.NETVB.NET and inand in J#J#

Value types and reference typesValue types and reference types All types derive fromAll types derive from System.ObjectSystem.Object

Page 37: .NET Framework Overview

The .NET The .NET LanguagesLanguagesC#, VB.NET, C++, J#, etc. C#, VB.NET, C++, J#, etc.

Page 38: .NET Framework Overview

..NET LanguagesNET Languages

.NET languages by Microsoft.NET languages by Microsoft C#, VB.NET, Managed C++, J#, F#, C#, VB.NET, Managed C++, J#, F#,

JScriptJScript .NET languages.NET languages by third partiesby third parties

Object Pascal, Perl, Python, COBOL, Object Pascal, Perl, Python, COBOL, Haskell, Oberon, Scheme, Smalltalk…Haskell, Oberon, Scheme, Smalltalk…

Different languages can be mixed in Different languages can be mixed in a single applicationa single application

Cross-language inheritance of types Cross-language inheritance of types and exception handlingand exception handling

Page 39: .NET Framework Overview

C# LanguageC# Language C# is mixture between C++, Java and C# is mixture between C++, Java and

DelphiDelphi Fully object-oriented by designFully object-oriented by design

Component-oriented programming Component-oriented programming modelmodel ComponentsComponents, , properties and eventsproperties and events No header files like C/C++No header files like C/C++ Suitable forSuitable for GUIGUI andand WebWeb applicationsapplications XML based documentationXML based documentation

InIn C# all data types are objectsC# all data types are objects Example: Example: 5.ToString()5.ToString() is a valid call is a valid call

Page 40: .NET Framework Overview

C# Language – ExampleC# Language – Example

C# is standardized byC# is standardized by ECMA and ECMA and ISOISO

Example of C# program:Example of C# program:using System;using System;

class NumbersFrom1to100class NumbersFrom1to100{{ static void Main()static void Main() {{ for (int i=1; i<=100; i++)for (int i=1; i<=100; i++) { { Console.WriteLine(i);Console.WriteLine(i); }} }}}}

Page 41: .NET Framework Overview

Framework Class Framework Class Library (FCL)Library (FCL)

Standard Out-of-the-box .NET APIsStandard Out-of-the-box .NET APIs

Page 42: .NET Framework Overview

Framework Class Framework Class Library (FCL)Library (FCL)

Framework Class Library is the standard Framework Class Library is the standard .NET Framework library of out-of-the-.NET Framework library of out-of-the-box reusable classes and components box reusable classes and components (APIs)(APIs)

Framework Class Library is the standard Framework Class Library is the standard .NET Framework library of out-of-the-.NET Framework library of out-of-the-box reusable classes and components box reusable classes and components (APIs)(APIs)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

ASP.NETASP.NETWeb Forms, MVC, AJAXWeb Forms, MVC, AJAXMobile Internet ToolkitMobile Internet Toolkit

WindowsWindowsFormsForms WPFWPF SilverlightSilverlight

Page 43: .NET Framework Overview

FCL NamespacesFCL Namespaces

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

ASP.NETASP.NETWeb Forms, MVC, AJAXWeb Forms, MVC, AJAXMobile Internet ToolkitMobile Internet Toolkit

WindowsWindowsFormsForms

WPF & SilverlightWPF & Silverlight

System.WebSystem.WebSystem.WebSystem.Web

System.Web.MvcSystem.Web.MvcSystem.Web.MvcSystem.Web.Mvc

System.WindowSystem.Windows.Formss.FormsSystem.WindowSystem.Windows.Formss.Forms

System.DrawinSystem.DrawinggSystem.DrawinSystem.Drawingg

System.WindowsSystem.WindowsSystem.WindowsSystem.Windows

System.Windows.MediaSystem.Windows.MediaSystem.Windows.MediaSystem.Windows.Media

System.Windows.MarkupSystem.Windows.MarkupSystem.Windows.MarkupSystem.Windows.Markup

System.ServiceModelSystem.ServiceModelSystem.ServiceModelSystem.ServiceModel System.ActivitiesSystem.ActivitiesSystem.ActivitiesSystem.Activities System.WorkflowSystem.WorkflowSystem.WorkflowSystem.Workflow

System.DataSystem.DataSystem.DataSystem.Data System.LinqSystem.LinqSystem.LinqSystem.Linq

System.Data.LinqSystem.Data.LinqSystem.Data.LinqSystem.Data.Linq

System.XmlSystem.XmlSystem.XmlSystem.Xml

System.Xml.LinqSystem.Xml.LinqSystem.Xml.LinqSystem.Xml.Linq System.Data.EntitySystem.Data.EntitySystem.Data.EntitySystem.Data.Entity

Page 44: .NET Framework Overview

Visual Studio IDEVisual Studio IDEPowerful Development Powerful Development Environment for .NETEnvironment for .NET

Page 45: .NET Framework Overview

Visual StudioVisual Studio Visual Studio is powerful IntegratedVisual Studio is powerful Integrated

Development Environment (IDE) for .NET Development Environment (IDE) for .NET DevelopersDevelopers Create, edit, compile and run .NET Create, edit, compile and run .NET

applicationsapplications Different languagesDifferent languages – – C#, CC#, C++, ++, VB.NET,VB.NET,

J#, …J#, … FlexibleFlexible code editorcode editor PowerfulPowerful debuggerdebugger Integrated with SQL ServerIntegrated with SQL Server andand IISIIS Strong support of Web services, WCF and Strong support of Web services, WCF and

WWFWWF

Page 46: .NET Framework Overview

Visual Studio Visual Studio (2)(2) Visual programmingVisual programming

Component-orientedComponent-oriented, , event basedevent based Managed and unmanaged codeManaged and unmanaged code Helpful wizards and editorsHelpful wizards and editors

Windows Forms DesignerWindows Forms Designer WCF / Silverlight DesignerWCF / Silverlight Designer ASP.NET Web Forms DesignerASP.NET Web Forms Designer ADO.NET / LINQ-to-SQL / XML Data ADO.NET / LINQ-to-SQL / XML Data

DesignerDesigner Many third party extensionsMany third party extensions

Page 47: .NET Framework Overview

Visual StudioVisual Studio IDEIDE

Page 48: .NET Framework Overview

.NET Framework .NET Framework OverviewOverview

Questions?Questions?

http://aspnetcourse.telerik.com