INTRODUCTION TO THE .NET FRAMEWORK

wrackbaaΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

106 εμφανίσεις

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

INTRODUCTION TO THE .NET FRAMEWORK

The .NET framework will run on any Windows PC running Windows 98
or higher. Visual Studio.NET will not run on Windows 98 or Windows
ME, but you don't need VS.NET to use the framework. In fact, the
framework contains all o
f the tools needed to compile an application
and deploy its components to the global assembly cache (GAC).

Future versions of Windows will likely include the .NET framework. The
current version of the framework is 1.1. Version 2.0 should be
released in la
te 2004 or early 2005.

There is a compact version of the framework that is used to create
applications for PDAs or mobile phones.

WHY .NET IS AN IMPROVEMENT

Writing software is not easy, especially if you're a Microsoft developer.
Technologies have come
and gone in recent years leaving developers
scrambling to learn the latest and greatest ways to create Web sites,
access databases, create components, and secure their applications.

Prior to .NET, it was difficult to incorporate code written in differing
l
anguages because each language has its own conventions and
limitations. It would have been nice to make an application that easily
accessed a database through VB while piggybacking on the power and
flexibility of C++.

.NET offers an object oriented view of

the Windows operating system.
It includes hundreds of classes that make up the most important
Windows
Kernel

objects. In fact, there is a seven volume set of books
sol
d by Microsoft that reference every object available in the
framework.

Security is built into .NET so programmers don't have to worry about
operating system security.

.NET applications consist of one or more assemblies. An assembly is an
EXE or DLL file.
Assemblies can include other DLL files or non
executable files such as GIFs or HTML pages. All files in the same
assembly share the same assembly version. This ensures that the
assembly has not been tampered with.

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

.NET doesn't use the registry to store in
formation about an application.
This information is stored in an application's directory within a
configuration file. The configuration file is written in XML. The great
thing about eliminating the registry from the picture is that you can
copy an applicat
ion's folder and it will still work as long as the
computer it's running on has the .NET framework installed.

All objects in the .NET framework inherit from the object named
System.object. When you program .NET you are generally extending
this class.

All

objects are released from memory when they are no longer
referenced due to the memory management built into the framework.

ALL .NET LANGUAGES ARE EQUAL

One of the neat things about the .NET framework is that it contains
classes for doing a lot of things
you relied on a programming language
to accomplish. This includes opening, reading and writing text files.

The Windows Forms class allows you to create windows and controls.
All .NET languages have access to these classes.

C# and VB.NET are roughly equiv
alent. However there are no true
pointers in VB.NET and you can't overload an operator. In C# you
cannot use the "On Error" style of error handling. You must use
structured error handling in Try/Catch/Finally blocks. Late binding is
much easier in VB.NET.

When deciding between VB.NET and C#, you should simply consider
which language will be easier to learn. If you are a C++ or Java
programmer, C# is easier to learn. VB6 programmers should obviously
gravitate to VB.NET.

THE .NET ARCHITECTURE

There are many
layers to the .NET framework. The graphic on page 17
of PMVBN illustrates the framework's layers.

The layers from the bottom up:


WINDOWS API
--
The set of functions you can call to
gain low level access to the operating system.


COM+
--
T
he .NET framework doe
s not contain its own
Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

component services functionality. It relies on the
existing COM+ technology.


COMMON LANGUAGE RUNTIME
--
The first layer
that belongs to .NET. It's responsible for memory
management, garbage collection, structured exception
handling and

multithreading. The runtime is contained
in a file named MSCorEE.dll. All net applications call a
function in this file when they begin executing.


BASE CLASS LIBRARY
--
Defines all the basic data
types beginning with System. Object and including all
other
data types in the framework. Classes also exist
for File I/O, threading, serialization, and security.
Languages must follow a Common Type System (CTS)
when using a .NET data type to expose fields,
properties, methods, and events.
Although most of
the base
classes are compiled into mscorlib.dll,
others can be found in other dll files, including
system.dll.



DATA/XML
--
Contain the .NET classes that work with
databases and XML. .NET stores many different types
of information in XML. The data portion of .NET is
known as ADO.NET. ADO.NET focuses on
disconnected recordsets, ones that maintain no
connection to the original data source.


ASP.NET/Windows Forms
--
Contain all of the
classes that generate the UI. ASP.NET consists of both
Web forms and XML Web services.


C
OMMON LANGUAGE SPECIFICATION (CLS)
--
A
set of specifications that a .NET language must must
follow including support for structured event handling,
zero bound arrays, and certain numeric data types.


THE .NET PROGRAMMING LANGUAGES
--
Every
.NET programming la
nguage produces managed code,
code that runs under the control of the CLR. Learning
another .NET language should be easy once you've
mastered one.

MICROSOFT INTERMEDIATE LANGUAGE (MSIL)

.NET compilers don't create machine language code the first time the
y
compile your application. They create IL instead. IL is human readable.
It's controversial because someone reading your IL can learn a lot
about how you created your application. IL is lower level than
Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

programming language code but higher level than mach
ine language
code. It doesn't deal with the CPU registers and is aware of exceptions
and object creation.

The ILDASM tool can display the IL for any executable created by a
.NET compiler. See page 27 to use ILDASM from the command line.

Visual Studio.NET

2003 contains an application that will obfuscate your
IL.

JUST IN TIME (JIT) COMPILER

No currently available CPU can run IL. The JIT compiler is located
within the .NET runtime. It converts IL to native code and executes it.
This is done only once per me
thod in the application's lifetime.
Successive calls to the same method access the compiled copy in
memory.

.NET applications run as fast as native code. Even better, since they
are not completely compiled before they are run, start up time is
usually neg
ligible.

However, you can no longer debug your code before it's compiled to
machine language as you could in previous versions of VB6 using
P
-
code.

Because IL isn't tied to a specific CPU, you should be able to run your
application on any PC that has the .NET Framework installed.

WORKING WITH ASSEMBLIES

No matter what type of application you create, it will be deployed in

the form of an assembly. Assemblies contain one or more executable
files known as managed modules. Managed modules contain both IL as
well as metadata that contains information about the types exposed in
the module and the types referenced by the module.

The graphic on page 35 of the big book shows how three .vb files are
converted by the compiler into a single module assembly.

You must use a tool named Assembly Linker if you want to create an
assembly with modules written in different languages or if the
assembly is going to contain nonexecutable files such as HTML, and
image files.

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

METADATA

The metadata in each managed module contains complete information
about each type defined in the module including the name, public
members, the signature (arguments re
quired/data types) for each
distinct method, and the private variables. Information about each
.NET type used by the module is also included in the metadata.

Metadata is primarily used to ensure that methods and fields are
accessed in an appropriate manner
. Metadata make a managed
module self
-
describing. Because of metadata, no external information
about an application needs to be stored in the system registry. This
allows XCOPY functionality to be enabled. XCOPY is simply a buzzword
for copying an applicat
ion from computer to computer by simply
pasting copies of the application folder from on each PC.

The entire .NET architecture is based on metadata. The .NET memory
manager uses metadata to figure out how much memory must be
allocated to a .NET object when

its created. Intellisense and the object
browser work as well as they do because of metadata. These two
features use reflection to gather information via metadata.

Each assembly contains a manifest. The manifest is a special metadata
section that contains

the names of all the files in the assembly as well
as its exposed types.

CODE VERIFICATION

The runtime makes sure that when a function or sub is called, the
correct number of arguments are passed to it. It also ensures that
pointers point to the correct d
ata type so the application doesn't read
or modify memory that doesn't belong to it. Because of this security,
you can run multiple applications within the same address space
(process) without worry.

The .NET Framework SDK comes with PEVerify.exe, a tool t
hat allows
system administrators to find out if a program passes the verification
test. Programmers will create safe code as long as all of their
functionality comes from .NET and not from COM, or direct calls to the
Windows API.

APPDOMAINS

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

An AppDomain is

a logical managed application


that runs inside of a
physical Windows process. It's logical because multiple AppDomains
can work inside of the same Windows process (as noted above).

AppDomains obviously use less memory and fewer resources than
traditional

Windows applications. They launch and end faster, and
scale better.

If two applications in the same AppDomain need to communicate, this
communication can call into each other quickly and easily as long as
the caller has the right to call the method in the

other application.

SECURITY

Managed code is secured by the common language runtime. The key
to .NET security is the permission object. There are three different
permission levels:

1.

Code Access Permissions
--
Access to that you perform on a
protected resource

such as printing, accessing the Windows
registry, and the Windows event log.

2.

Identity Permissions
--
Represent the identity of the code an
contain the name of the assembly, the Web site and URL where
the code came from and the identity of the publisher. As

you can
see, identity is an issue when potentially malicious code is
downloaded from the Internet.

3.

Role
-
based Security Permissions
--
The user who is running the
code.

At this point it looks like there might be a whole course designed to
discuss .NET secu
rity.

THE .NET FRAMEWORK CLASS LIBRARY

This library is a collection of classes that .NET applications use to
access the OS, file system, databases, as well as many other
resources. Since there are 1000's of classes in the .NET Class Library,
they are organ
ized into namespaces. A namespace is a logical
grouping of classes. They can also contain other namespaces. For
example the System namespace also contains the System.Web
namespace.

It's important to note that a namespace is not necessarily a single file.
T
hey can be split into multiple DLL files.

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

Page 42
-
45 of the big book contain the most important namespaces in
the .NET framework.

ADO.NET

System.Data and its nested namespaces make up ADO.NET. ADO.NET
focuses on client side data access/manipulation.

There
is a whole course being planned for .NET data access.

OTHER NAMESPACES

There are classes in the framework that aren't underneath the System
namespace. For example, the Microsoft.Win32 namespace contains
classes that are useful to programmers creating Windo
ws applications.
The Microsoft.VisualBasic namespace allows programmers to code in
VB.NET using syntax familiar to VB6 programmers


SETTING A REFERENCE TO A NAMESPACE IN VS.NET

A namespace can't be used unless a reference is set to it in your
project. The following namespaces are accessible from all of your
applications by default:

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes


If you need to add a reference, right click on your project name and
choose "add reference."

Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes


Find the reference you need to add, click select and then OK.


Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes

You do not have
to explicitly reference the mscorlib.dll, which is the
assembly that contains the
System

namespace; the Visual Basic or
Visual C# compiler always references mscorlib.dll.

THE OBJECT BROWSER AND CLASS VIEW WINDOW

You may be familiar with the object browser
from VB6. The .NET
version is improved as it shows the base class which a type is derived
from as well as all the interfaces implemented by that type.


You can click the find button on the object browser's toolbar to search
for objects that contain a character string.


Raritan Valley Community College

CIS235Y


Microsoft .Net Framework

Course Notes


You can also add .NET components that aren't referenced by the
current project.

The class view window allows y
ou to drill down until you reach
individual fields and methods. You can create a new folder and drag
the types and methods to the folder for quick access.

WEEKLY LINKS

.NET Skills Assessment

.NET Framework in Visual Studio

The Heap vs. The Stack

The Mono Project
--
Dot Net on Linux