Title: Module 1: Overview of the Microsoft .NET Framework
1Module 1 Overview of the Microsoft .NET Framework
2Overview
- Overview of the Microsoft .NET Framework
- Writing a .NET Application
- Compiling and Running a .NET Application
- Working with Components
3Overview of the Microsoft .NET Framework
- The .NET Framework
- Common Language Runtime
- The .NET Framework Class Library
- ADO.NET Data and XML
- What is an XML Web Service?
- Web Forms and Services
4The .NET Framework
VB
C
C
Perl
Python
Web Services
User Interface
ASP.NET
ADO.NET Data and XML
.NET Framework Class Library
Common Language Runtime
Win32
5Common Language Runtime
.NET Framework Class Library Support
Class Loader
6The .NET Framework Class Library
- Spans All Programming Languages
- Enables cross-language inheritance and debugging
- Integrates well with tools
- Is Object-Oriented and Consistent
- Enhances developer productivity by reducing the
number of APIs to learn - Has a Built-In Common Type System
- Is Extensible
- Makes it easy to add or modify framework features
- Is Secure
- Allows creation of secure applications
7ADO.NET Data and XML
8What Is an XML Web Service?
A programmable application component accessible
via standard Web protocols
9Web Forms and Services
System.Web
Services
UI
Description
HtmlControls
Discovery
WebControls
Protocols
Caching
Security
SessionState
Configuration
10Writing a .NET Application
- Using a Namespace
- Defining a Namespace and a Class
- Entry Points, Scope, and Declarations
- Console Input and Output
- Case Sensitivity
11Using a Namespace
- Classes Can Be Fully Referenced
- Or the Namespace of a Class Can Be Referenced
- No need to fully qualify contained class names
// declares a FileStream object System.IO.FileStre
am aFileStream
using System.IO ... FileStream aFileStream
12Defining a Namespace and a Class
- C Supports Creation of Custom Namespaces and
Classes Within Those Namespaces
namespace CompCS public class StringComponent
...
13Entry Points, Scope, and Declarations
- In C, the External Entry Point for a Program Is
in a Class - C Supports the Use of a Period As a Scope
Resolution Operator - In C, Objects Must Be Declared Before They Can
Be Used and Are Instantiated Using the New Keyword
class MainApp public static void Main() .
. .
Console.WriteLine ("First String")
Lib.Comp myComp new Lib.Comp()
14Console Input and Output
- Console Class Methods
- Read, ReadLine, Write, and WriteLine
Console.WriteLine("Hello World using C!")
15Case Sensitivity
- Do Not Use Names That Require Case Sensitivity
- Components should be fully usable from both
case-sensitive and case-insensitive languages - Case should not be used to distinguish between
identifiers within a single name scope - Avoid the Following
class customer ... class Customer ... void
foo(int X, int x)
16Compiler Options
- Compile Directly from a Command Prompt Window
- Use /t to indicate target
- Use /reference to reference assemblies
gtcsc HelloDemoCS.cs
gtcsc /texe HelloDemoCS.cs
gtcsc /texe /referenceassemb1.dll HelloDemoCS.cs
17Demonstration Hello World
18 Compiling and Running a .NET Application
- The Process of Managed Execution
- Metadata
- Microsoft Intermediate Language
- Assemblies
- Common Language Runtime Tools
- Just-In-Time Compilation
- Application Domains
- Garbage Collection
19The Process of Managed Execution
EXE/DLL(MSIL and metadata)
SourceCode
Compiler
ClassLibraries(MSIL and metadata)
Class Loader
JIT Compilerwith optionalverification
Call to anuncompiledmethod
Trusted,pre-JITedcode only
ManagedNative Code
Execution
Security Checks
Runtime Engine
20Metadata
- Declarative Information Emitted at Compile Time
- Included with All .NET Framework Files and
Assemblies - Metadata Allows the Runtime to
- Load and locate code
- Enforce code security
- Generate native code at runtime
- Provide reflection
21Microsoft Intermediate Language
- Produced by Each Supported Language Compiler
- Converted to Native Language by the Common
Language Runtime's JIT Compilers
22Assemblies
Managed Module (MSIL and Metadata)
Managed Module (MSIL and Metadata)
Assembly
Manifest
Multiple Managed Modules andResource FilesAre
Compiled to Produce an Assembly
Resource Files
23Common Language Runtime Tools
- Runtime Utilities for Working with MSIL
- MSIL Assembler (ilasm.exe) produces a final
executable binary - MSIL Disassembler (ildasm.exe) inspects metadata
and code of a managed binary
24Demonstration Using the MSIL Disassembler
25Just-In-Time Compilation
- Process for Code Execution
- MSIL converted to native code as needed
- Resulting native code stored for subsequent calls
- JIT compiler supplies the CPU-specific conversion
26Application Domains
- Historically, Process Boundaries Used to Isolate
Applications - In the Common Language Runtime, Application
Domains Provide Isolation Between Applications - The ability to verify code as type-safe enables
isolation at a much lower performance cost - Several application domains can run in a single
process - Faults in One Application Cannot Affect Other
Applications
27Multimedia Application Loading and Single-File
Assembly Execution
28Garbage Collection
- Garbage Collection Provides Automatic Object
Memory Management in the .NET Framework - You No Longer Need to Track and Free Object Memory
29Working with Components
- Creating a Simple .NET Framework Component
- Creating a Simple Console Client
- Creating an ASP.NET Client
30Creating a Simple .NET Framework Component
- Using Namespaces and Declaring the Class
- Creating the Class Implementation
- Implementing Structured Exception Handling
- Creating a Property
- Compiling the Component
31using System namespace CompCS public class
StringComponent private string
StringSet public StringComponent()
StringSet new string "C
String 0", "C String 1",
"C String 2", "C String 3"
public string GetString(int
index) if ((index lt 0) (index gt
StringSet.Length)) throw new
IndexOutOfRangeException()
return StringSetindex public int
Count get return StringSet.Length
- using System
- namespace CompCS
- public class StringComponent
- private string StringSet
- public StringComponent()
- StringSet new string
- "C String 0",
- "C String 1",
- "C String 2",
- "C String 3"
-
-
- public string GetString(int index)
- if ((index lt 0) (index gt
StringSet.Length)) - throw new IndexOutOfRangeException()
-
- return StringSetindex
-
- public int Count
32Compiling the Component
- Use the /targetlibrary Switch to Create a DLL
- Otherwise, an executable with a .dll file
extension is created instead of a DLL library
csc /outCompCS.dll /targetlibrary CompCS.cs
33Creating a Simple Console Client
- Using the Libraries
- Instantiating the Component
- Calling the Component
- Building the Client
34Using the Libraries
- Reference Types Without Having to Fully Qualify
the Type Name - If Multiple Namespaces Contain the Same Type
Name, Create a Namespace Alias to Remove
Ambiguity
using CompCS using CompVB
using CSStringComp CompCS.StringComponent usin
g VBStringComp CompVB.StringComponent
35using System using CSStringComp
CompCS.StringComponent using VBStringComp
CompVB.StringComponent class MainApp
public static void Main() CSStringComp
myCSStringComp new CSStringComp() Console.Writ
eLine("Strings from C StringComponent") for
(int index 0 index lt myCSStringComp.Count
index) Console.WriteLine(myCSStringComp.G
etString(index)) VBStringComp
myVBStringComp new VBStringComp() Console.Writ
eLine("\nStrings from VB StringComponent") for
(int index 0 index lt myVBStringComp.Count
index) Console.WriteLine(myVBStringComp.G
etString(index))
- using System
- namespace CompCS
- public class StringComponent
- private string StringSet
- public StringComponent()
- StringSet new string
- "C String 0",
- "C String 1",
- "C String 2",
- "C String 3"
-
-
- public string GetString(int index)
- if ((index lt 0) (index gt
StringSet.Length)) - throw new IndexOutOfRangeException()
-
- return StringSetindex
-
- public int Count
36Building the Client
- Use the /reference Switch to Reference the
Assemblies That Contain the StringComponent Class
csc /referenceCompCS.dll,CompVB.dll?
/outClientCS.exe ClientCS.cs
37Demonstration Creating a Windows Forms Client
38Creating an ASP.NET Client
- Writing the HTML for the ASP.NET Application
- Coding the Page_Load Event Handler
- Generating the HTML Response
39Writing the HTML for the ASP.NET Application
- Specify Page-Specific Attributes Within a Page
Directive - Import the Namespace and the Physical Assembly
- Specify Code Declaration Blocks
lt_at_ Page Language"C" Description"ASP.NET
Client" gt
lt_at_ Import Namespace"CompCS"gt lt_at_ Import
Namespace"CompVB"gt
ltscript language"C" runatservergt ...
lt/scriptgt
40Coding the Page_Load Event Handler
void Page_Load(Object sender, EventArgs
EvArgs) StringBuilder Out new
StringBuilder("") int Count 0 //
Iterate over component's strings and concatenate
Out.Append("Strings from C Componentltbrgt")
CompCS.StringComponent myCSStringComp new
CompCS.StringComponent() for(int index 0
index lt myCSStringComp.Count index)
Out.Append(myCSStringComp.GetString(index)
) Out.Append("ltbrgt") //
Message.InnerHtml Out.ToString()
41Generating the HTML Response
- Specify the Body of the HTML Response
ltbodygt ltspan id"Message" runatserver/gt lt/bodygt
42Demonstration Testing the ASP.NET Client
43Introduction to Application Deployment
- Common Concepts
- Simple Applications
- Componentized Applications
- Configuration and Distribution
44Common Concepts
- Classes and Types Used in .NET Framework
Applications Are - Organized in a hierarchy of namespaces
- Stored in PE files, such as DLLs and EXEs
- Fully described by metadata
- Assemblies
- Are made up of one or more PE files
- Contain a manifest that identifies the assembly
and its files - Specify exported and imported classes and types
- Are units of deployment, reuse, and versioning
45Simple Applications
- Require .NET Runtime Be Installed on Local
Computer - Can Be Run Directly from a File Server or Copied
Locally - Make No Registry Entries
- Cannot Break Another Application
- Eliminate DLL Hell
- Can Be Uninstalled by Deleting Locally Copied
File(s)
46Componentized Applications
- Assemblies Private to an Application
- Same as a simple application
- Assemblies Private to Related Applications
- Deployed into a common subdirectory
- Assemblies Shared with Other Unrelated
Applications - Require a strong name and version information
- Deployed into the global assembly cache
47Configuration and Distribution
- Configuration
- Maintained in plain-text files
- Deployment
- Common distribution formats, such as a .CAB file
or a .MSI file - Common distribution mechanisms, such as
Windows 2000 IntelliMirror or Microsoft Systems
Management Server
48 Application Deployment Scenarios
- A Simple Application
- A Componentized Application
- Specifying a Path for Private Assemblies
- A Strong-Named Assembly
- Deploying Shared Components
- A Versioned Assembly
- Creating Multiple Versions of a Strong-Named
Assembly - Binding Policy
- Deploying Multiple Versions of a Strong-Named
Assembly
49A Simple Application
- Use the Microsoft Intermediate Language
Disassembler (Ildasm.exe) to Examine the Assembly
Manifest - Version information
- Imported types
- Exported types
- Deploy the Application by
- Running the executable file directly from a file
server, or - Installing it locally by copying the file
- Uninstall the application by deleting the file
50Componentized Application
- Assembly Component to Be Used by Application
- Assembly Stringer.dll is built from Stringer.cs
as follows - Client Needs to Reference Assembly
- Deployment by File Server or Local Copy
csc /targetlibrary Stringer.cs
csc /referenceStringer.dll Client.cs
51Specifying a Path for Private Assemblies
- Specifying a Directory From Which to Load Private
Assemblies. - Client.exe.config file specifies a privatePath
tag - Configuration Files XML Tags Are Case-Sensitive
ltconfigurationgt ltruntimegt
ltassemblyBinding xmlns"urnschemas-microso
ft-comasm.v1"gt ltprobing
privatePathMyStringer"/gt lt/assemblyBindinggt
lt/runtimegt lt/configurationgt
52A Strong-Named Assembly
- Global Assembly Cache
- Contains assemblies shared by unrelated
applications - Strong Names Are Required for Assemblies in the
Cache - Generate a public-private key pair
- Add code to source file to specify version and
key information - Compile
sn k orgKey.snk
if STRONG assembly System.Reflection.AssemblyVe
rsion("1.0.0.0") assembly System.Reflection.Ass
emblyKeyFile("orgKey.snk") endif
csc /defineSTRONG /targetlibrary
/outAReverser.dll? AReverser.cs