11
Unit 01
Getting started with .NET
Framework 4.0
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Topics
2
Benefits of .NET Framework, Architecture of .NET
Framework 4.0,
Components of .NET Framework 4.0: CLR, CTS, Metadata
and Assemblies,
.NET Framework Class Library, Windows Forms,
ASP .NET and ASP .NET AJAX, ADO .NET,
Windows workflow Foundation, Windows Presentation
Foundation, Windows Communication Foundation, Windows
Card Space and LINQ.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Understanding the Previous State of
Affairs
3
Life as a C/Win32 API Programmer
It is a most Powerful language[Pointer] and Structured
Programming Language[complex for coding big projects]
Data is not secure
Manual memory management [no automatic memory
management], ugly pointer arithmetic [difficult to
use arithmetic operations], ugly syntactic constructs [array
out
of bound]
Not a OOP language[Encapsulation, Polymorphism, Inheritance ]
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont.
4
Life as a C++/MFC Programmer
Advantages:
Root is C
Famed Pillars of OOP [ Encapsulation, Polymorphism, Inheritance ]
Data is secure
Support for the generic programming language
Disadvantages:
C++ with MFC is still complex
not truly object oriented
not suitable for developing web applications
does not support versioning i.e. creation and management
of multiple versions of Software
It is not type-safe [ array unbound, pointer concept ]
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont.
5
Life as a Java/J2EE Programmer
Advantages:
It is completely OOP language and root of C++
It is a platform independent
It eliminates pointers which is major concern in C and C++
It contains large number of pre-defined packages that
contain various type denitions
Programmers can build pure Java applications complete
with database connectivity, messaging support,
web-enabled front ends, and a richer user interface
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont.
6
Disadvantages:
Java is a very elegant language [ must use of Java
front-to-back during development cycle ]
No language freedom!
Java applets are not supported by all the browsers
Pure Java is not suitable for graphic intensive
problems (E.g. 3D game)
No cross-language integration
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Evolution of .NET
.NET Version
4.5
4.0
3.5
3.0
2.0
1.1
1.0
By Prof. Suma M G, Dept. of MCA
Year
IDE and version
2
01
0
2008
Nov 19 2007
Nov 06 2006
Nov 07 2005
2003
Feb 13 2002
VS .NET 2010 IDE
Announced
VS .NET 2008 IDE
WinFX
VS .NET 2005 IDE
VS .NET 2003 IDE
VS .NET 2002 IDE
RNSIT Bengaluru
Benefits of .NET Framework
8
The following are the benefits of .Net Framework:
Consistent Programming Model
Provides a consistent object-oriented programming
model across different language.
Cross-Platform Support
Specifies that any windows platform that supports CLR
can execute .NET application
Language Interoperability
Enables code written in different languages to interact
with each other.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Benefits of .NET Framework(cont..)
9
The following are the benefits of .Net Framework:
Automatic Management of Resource
Specifies that in .NET, you do not need to manually free
the application resources, such as files, memory, network and
database connection.
Ease of Deployment
Specifies that the .NET Framework installs applications
or components that do not affect the existing applications.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Architecture of .NET Framework 4.0
10
.NET Framework 4.0
User Interface
ASP.NET
(MVC,
WebForms,
Dynamic
Data)
Data Access
Services
Windows
Presentation
Foundation
Windows
Communication
Foundations
Data
Services
Velocity
WinForms
Windows workflow
foundation
ADO
.NET
LINQ
to SQL
Entity
Framework
Core
Parallel
Extensions
Managed
Extensibility
Framework
LINQ
Languages
Dynamic
Language
Runtime
Base Class
Library
Common Language Runtime
Common Type Specification
By Prof. Suma M G, Dept. of MCA
Common Language Specification
RNSIT Bengaluru
Cont..
11
The application development in the .NET Framework
4.0 can be executed in a distributed environment.
The latest version of .NET provides a framework that
helps in developing
Portable
Scalable
robust
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Components of .NET Framework 4.0
12
The component of .NET Framework 4.0 architecture are as
follows:
Common Language Runtime(CLR)
Common Type System(CTS)
Metadata and Assemblies
.NET Framework class library
Windows Forms
ASP.NET and ASP.NET AJAX
ADO.NET
Windows Workflow Foundation
Windows Presentation Foundation
Windows Communication Foundation
Windows CardSpace
LINQ
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Common Language Runtime(CLR)
13
CLR is a Execution Engine for .NET Framework application
CLR is one of the most important components of .NET
Framework, provides a run-time environment to run the
code and provides various services to develop the application
easily.
Services provided by CLR are:
Memory Management
Exception handling
Debugging
Security
Thread execution
By Prof. Suma M G, Dept. of MCA
Language Integration
Code execution
Code Safety
Verification
Compilation
RNSIT Bengaluru
Cont..
14
CLR ensuring interoperability between the codes.
.NET supports two kind of coding
Managed Code: used to describe the code targeting
Unmanaged Code: code that cannot be directly hosted
CLR- CLR is the heart of the .Net framework and it does 4
primary important things CLRs provide the security to protected resources and operation by
preventing unauthorized access. This is called as Code Access
Security(CAS).
The runtime automatically releases the objects when they are no longer in
use.(GC)
It implements a strict type and code-verification infrastructure(CTS)
IL to Native translation.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
CLR Execution Model
15
C#
VB.NET
C++.NET
Compiler
Compiler
Compiler
Managed Assembly
IL Code
Code
Assembly
IL Code
Assembly
IL Code
Source
Code
Common Language Runtime
JIT Compiler
Native Code
Operating System
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Unmanaged
Code
The Example: Hello, .NET-World!
HelloWorld.cs:
class HelloWorldApp {
static void Main () {
System.Console.WriteLine("Hello, .NET-World!");
}
}
Compile and create assembly (w/ C# compiler):
> csc HelloWorld.cs
Assembly:
HelloWorld.exe
(3072
Byte!)
View metadata and CIL code
(w/ IL disassembler):
> ildasm HelloWorld.exe
RNSIT Bengaluru
By Prof. Suma M G, Dept. of
MCA
16
CIL and Metadata
IL assembler code (= Metadata + CIL) of method Main:
.method private hidebysig static void Main() cil
managed {
.entrypoint
.maxstack 1
ldstr "Hello, .NET-World!"
call void
[mscorlib]System.Console::WriteLine(string)
ret
}
RNSIT Bengaluru
By Prof. Suma M G, Dept. of
MCA
17
CLR
.NET
Source
Code
.NET Compiler
*.DLL or *.EXE
(CIL, metadata, manifest)
mscoree.dll
Class Loader
Base Class
Libraries
(mscorlib.dll)
Jitter
Platform
Specific code
mscoree.dll: Micro Soft Common
Object Runtime Execution Engine
Execute
.NET Execution Engine
Managed Code
19
Managed code is the code that is executed by the CLR.
The process of executing a piece of managed code is as follows:
1. Selecting a language compiler
2. Compiling the code to IL
3. Compiling IL to native code
Source Code
Any language written code
of .NET Framework
Native Compiler (Language Specific)
4. Executing the code
.IL must be converted into CPU-specific code MSIL Code
Language independent
within .Net Framework
by the Just-in-Time(JIT) compiler, before the
JIT(Just-in-Time) Compiler
execution of the code.
.The runtime locates and extracts the
Executable Code
metadata from the file during execution.
.While executing the application, a JIT
compiler translates the IL into native code.
By Prof. Suma M G, Dept. of MCA
CPU
RNSIT Bengaluru
Output
Unmanaged Code
20
Unmanaged code is the code that is not executed by the CLR.
CCW (COM
Example: C++, VB, ASP. . . . .
callable wrapper)
Any language written
Source Code
Unmanaged code can be unmanaged
(Runtime
source code and unmanaged RCW
callable wrapper)
compile code.
Unmanaged code is executed
with help of wrapper classes.
Wrapper classes are of two types:
code of .NET Framework
Native Compiler (Language Specific)
MSIL Code
Language independent
within .Net Framework
JIT(Just-in-Time) Compiler
Executable Code
CCW (COM callable wrapper) and
RCW (Runtime Callable Wrapper).
CPU
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Output
Memory Management
21
CLR provides during managed execution is the automatic
memory management.
CLR uses the garbage collector to
manage the allocation and
release of the memory for an application.
Advantages:
For the developers since it reduces the burden of writing codes
to manage memory while developing managed applications.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Common Type System(CTS)
22
CTS defines the rules for declaring, using, and managing
types at runtime.
It is an integral part of the runtime for supporting crosslanguage communication.
The common type system performs the following functions:
enables cross-language integration, type safety, and highperformance code execution.
provides an object-oriented model for implementation of
many programming languages.
defines rules that every language must follow which runs
under .NET framework like C#, VB.NET, F# etc. can interact
with each other.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont
23
CTS can be classified into two data types,
Value Types
Reference Type
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Metadata and Assemblies
24
A metadata is binary information that describes your program,
stored in a CLR Portable executable(PE) file or the memory.
Assemblies is a logical unit that consists of 4 elements as
follows:
Manifest
Metadata
IL code(static or dynamic)
Set of resources[bitmaps, jpeg]
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Metadata
25
A metadata is binary information that describes your program,
stored in a CLR Portable executable(PE) file or the memory.
The metadata contains the following:
Assembly information, which includes the metadata identity that can
be name, version, culture, public key, the types of assemblies, other
reference assemblies, and security permissions.
Information about types, such as name, visibility, base class,
interfaces used, and members(methods, fields, properties, events, and
nested types)
Attribute information that modifies the types and members of a class.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Assemblies
26
An assembly contains a self-describing binary file that can be
either Dynamic Link Library(DLL) or Executable(EXE).
It also contains a collection of types, such as classes, interfaces
and structures.
There are two types of assemblies:
Single assembly
Multiple assembly
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Single assembly
27
Single assembly: can contain multiple code files of single
code file can have more than one assembly.
OR
When the components of an assembly is grouped in a single
physical file, it is known as Single-file assembly.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Multi file assemblies
28
Multi file assemblies:
are composed of numerous .NET binaries, each of which is
called as a module.
When you building multi-le assemblies, one of these
modules must contain manifest and The other related
modules contain a module level manifest, CIL, and
type metadata.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Static and Dynamic assemblies
29
Static assemblies are those Assemblies which are
stored on the disk permanently.
They include interfaces, classes and resources.
These assemblies are stored in PE(Portable executable)
files on a disk.
are not loaded directly from the memory instead they are
directly loaded from the disk when CLR requests for them
Dynamic assemblies are those assemblies which are
not stored on the disk before execution in fact after
execution they get stored on the disk.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Manifest
30
Contains the assembly metadata needed for providing
the assemblys version requirements and security
identity.
manifest of HelloWorld.exe:
.assembly extern mscorlib {
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 1:0:3300:0
}
.assembly HelloWorld {
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module HelloWorld.exe
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
31
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
32
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Global Assembly Cache
33
The Global Assembly Cache (GAC) is a folder in Windows
directory to store the .NET assemblies that are specifically
designated to be shared by all applications executed on a
system.
Note:
The assemblies must be sharable by registering them in the GAC,
only when needed.
Otherwise, they must be kept private.
Further, it is not mandatory to install the assemblies in the
GAC to make them accessible to the COM interop or
unmanaged code.
Note: COM interop is a service that enables .NET Framework objects to
communicate with COM objects.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont.
34
Each assembly is accessed globally without any conflict by
identifying its name, version, architecture, culture and public
key.
You can deploy an assembly in GAC by using any one of the
following:
An installer that is designed to work with the GAC
The GAC tool known as Gacutil.exe
The Windows Explorer to drag assemblies into the cache.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Strong Name Assembly
35
A Strong Name contains the assemblys identity, that is, the
information about the assemblys name, version number,
architecture, culture and public key.
Using Microsoft Visual Studio .NET and other tools, you can
provide a strong name to an assembly.
By providing strong names to the assembly, you can ensure
that assembly is globally unique.
Benefits:
Provides uniqueness to the names by generating a private key.
Ensures that a version of the assembly you are using comes from the
same publisher that created the version the application was built with
Facilitates integrity check, which ensures that the contents of the
assembly do not change since its last build.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Private and Shared Assembly
36
A single application uses an assembly, then it is called as a
private assembly.
Assemblies that are placed in the Global Assembly cache so
that they can be used by multiple applications, then it is called
as a shared assembly.
Side-By-Side Execution Assembly:
The process of executing multiple versions of an application
or an assembly is known as side-by-side execution.
Strong naming of .NET assembly is used to provide unique
assembly identity by using the sn.exe command utility.
Store it in to the GAC
Load these assemblies at runtime.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
.NET Framework class library
37
.NET applications, components, and controls are built on
the foundation of .NET Framework types.
These entities perform the following functions:
Representing base data types and exceptions
Encapsulating data structures
Performing input/output operations
Accessing information about loaded types
Calling .NET Framework security checks
Facilitating data access, rich client-side Graphical User
Interface(GUI), and server-controlled, client-side GUI
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont.
38
The Framework Class Library(FCL)
is a huge library of reusable types meant to use by managed
heap.
is made up of a hierarchy of namespaces that expose classes,
structures, interfaces, enumerations, and delegates.
Example: System.Data.SqlClient
More than 20,000 classes in FCL
Note: All types must have a base class.
System.Object type is a base class for all types in .Net
framework.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont
39
Components
Windows Forms
ASP.NET and
ASP.NET AJAX
Meaning
Is the graphical representation of any window displayed in an
application
Is a web-development model, which is used to deliver
interactive and data driven web applications over the internet.
Features:
Better Performance,
Improved Security[forms, windows]
Great Scalability
Cookie less Sessions
AJAX, which is also know as Atlas, is used as an extension
for ASP.NET to develop and implement the AJAX
functionality.
ASP.NET AJAX has both side client and server components
to develop the web applications, which can update the
information on a web application without reloading the page
completely.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru
Cont
Components
ADO.NET
40
Meaning
Is a technology used for working with data and databases of all
types.
It provides access to data sources, such as Microsoft SQL
Server, data sources exposed through OLE DB, and XML
Windows
WorkFlow
Foundation
Is a technology introduced by Microsoft, which provides a
programming model for building workflow based applications on
windows.
Ex: workflow runtime, workflow designer, and a rules engine.
Window
Presentation
Foundation
Provides the base for building applications and a clear separation
between the user interface and the business logic.
Ex: building 2D/3D graphics, animations
Windows
Communication
Foundation
Is one of the technology introduced by Microsoft in .NET
framework 3.0 for building and running connected systems.
Ex: Web Services
Windows
CardSpace
Is a client software provided by Microsoft that improves the safety
of accessing resources and helps in sharing personal information
on the internet.
By Prof. Suma M G, Dept. of MCA
RNSIT Bengaluru