Вы находитесь на странице: 1из 4

The role of the .

NET CLR in creating a global development framework Page 1 of 4

TechRepublic : A ZDNet Tech Community

The role of the .NET CLR in creating a


global development framework
by Sanders "Kaufman, Jr." | Sep 09, 2002 7:00:00 AM

Tags: Sanders Kaufman, Jr.

Takeaway: The Common Language Runtime (CLR) is an integral part of the .NET Framework
that promises to let developers employ their cross-language skills in one master architecture.

The .NET Framework relies heavily on the core premise of the Common Language Runtime
(CLR), which .NET uses to translate various programming languages into Intermediate
Language (IL). IL is the syntax used to send, receive, and manage .NET signals.

You can use any programming language that conforms to the Common Language Specification
(CLS) to build .NET applications. Developers may come to a project with a variety of
programming backgrounds, including disparate languages. But as long as the developers have a
strong understanding of the .NET Framework, they can use their skills on a project.

First of two parts


This is the first of two articles that will discuss the core value of the CLR in Microsoft's plans
for .NET.

How does CLR work?


Within the domain of CLR are executables (consisting of code, data, and metadata), assemblies
(consisting of a manifest and zero or more modules), and the Common Type System (CTS)
convention set. When programmers write code in their favorite languages, that code is
translated into IL prior to being compiled into a portable executable (PE).

Executables
The main difference between a Windows PE and a .NET PE is that the Windows PE is executed
by the operating system, but .NET PEs are turned over to the .NET Framework’s CLR.
Recognition of a PE as being .NET or Windows occurs because of the Common Object File
Format (COFF) used by Windows operating systems. The COFF specifies two parts of any file:
the file data itself and a bunch of header data describing the contents of the data portion. Note:
To allow all Microsoft platforms to handle COFF modifications that enable .NET PEs, Microsoft
has released new loaders for all of .NET's supported systems (98, 2000, and Me).

Metadata
Metadata is information about a PE. In COM, metadata is communicated through
nonstandardized type libraries. In .NET, this data is contained in the header portion of a COFF-
compliant PE and follows certain guidelines; it contains information such as the assembly’s
name, version, language (spoken, not computer—a.k.a., “culture”), what external types are

http://articles.techrepublic.com.com/5100-10878_11-1050276.html 6/2/2010
The role of the .NET CLR in creating a global development framework Page 2 of 4

referenced, what internal types are exposed, methods, properties, classes, and much more.

The CLR uses metadata for a number of specific purposes. Security is managed through a public
key in the PE’s header. Information about classes, modules, and so forth allows the CLR to
know in advance what structures are necessary.

The class loader component of the CLR uses metadata to locate specific classes within
assemblies, either locally or across networks. Just-in-time (JIT) compilers use the metadata to
turn IL into executable code.

Other programs take advantage of metadata as well. A common example is placing a Microsoft
Word document on a Windows 2000 desktop. If the document file has completed comments,
author, title, or other Properties metadata, the text is displayed as a tool tip when a user hovers
the mouse over the document on the desktop. You can use the Ildasm.exe utility to view the
metadata in a PE. Literally, this tool is an IL disassembler.

Interoperability
Different types of files are handled by two different virtual systems in Windows and .NET. If a
Windows executable is to interoperate with the .NET Framework, it interfaces with a COM
wrapper for the desired .NET functionality, instead of accessing the functionality directly.
Similarly, if a .NET application utilizes Windows (COM) objects, it needs a set of classes that
expose the functionality, instead of accessing it directly. This communication between .NET and
Windows is called “interoperability.” Included in the .NET SDK are two sets of two tools each.
One set is for .NET-to-COM operations, and the other is for COM-to-.NET operations.

The first pair of tools consists of Regasm.exe and Tlbexp.exe. Regasm.exe registers a .NET
Assembly in the Windows registry. Once this is done, the assembly is exposed as a COM object
to the Windows OS. Developers who wish to access .NET Assemblies as COM objects in their
own applications can use the Tlbexp.exe utility to export a Type Library TLB file to be
referenced by their applications. The properties and methods of .NET Assembly are available,
just as with any other COM object.

The second pair of tools consists of TlbImp.exe and Xsd.exe. TlbImp.exe is run against a TLB
file to create a .NET Assembly in the form of a dynamic-link library (DLL) file.

Custom types in .NET are described through XML Schema Definitions (XSDs). When you run
the Xsd.exe utility against an existing XSD file with the “/c” switch, the schema is converted to a
C# class definition. As a sidenote, Xsd.exe also generates an XSD file from a .NET Assembly
(using metadata in the COFF headers) when run against a .NET PE.

Assemblies
A .NET Assembly contains all the metadata about the modules, types, and other elements it
contains in the form of a “manifest.” The CLR loves assemblies because differing programming
languages are just perfect for creating certain kinds of applications. For example, COBOL stands
for Common Business-Oriented Language because it’s tailor-made for creating business apps.
However, it’s not much good for creating drafting programs. Regardless of what language you
used to create your modules, they can all work together within one Portable Executable
Assembly.

Hierarchy

http://articles.techrepublic.com.com/5100-10878_11-1050276.html 6/2/2010
The role of the .NET CLR in creating a global development framework Page 3 of 4

There’s a hierarchy to the structure of .NET code. That hierarchy is “Assembly -> Module ->
Type -> Method." Let’s say you want your computer to calculate your mortgage. You’d create a
method called “fnCalculateMortgage” that returns an amortization table.

You could create a whole stand-alone application for this purpose, or you could make it one
method of a larger collection of functions (called a “type”) that you name
“libFinancialFunctions." This library of financial functions could include real-time functions to
transfer funds between accounts and other financial functions. The type, in turn, is contained
within a module of IL code called “MyAccounting” that contains all the financial and accounting
functions your business uses. Finally, the MyAccounting module could be one of several in the
final assembly, called “MyMIS,” which contains all your business management and operations
functions.

Intermediate language
Assemblies are made up of IL code modules and the metadata that describes them. Although
programs may be compiled via an IDE or the command line, in fact, they are simply translated
into IL, not machine code. The actual machine code is not generated until the function that
requires it is called. This is the just-in-time, or JIT, compilation feature of .NET.

JIT compilation happens at runtime for a variety of reasons, one of the most ambitious being
Microsoft's desire for cross-platform .NET adoption. If a CLR is built for another operating
system (UNIX or Mac), the same assemblies will run in addition to the Microsoft platforms. The
hope is that .NET assemblies are write-once-run-anywhere applications. This is a .NET feature
that works behind-the-scenes, ensuring that developers are not limited to writing applications
for one single line of products. No one has demonstrated whether or not this promise will ever
truly materialize.

CTS/CLS
The MSIL Instruction Set Specification is included with the .NET SDK, along with the IL
Assembly Language Programmers Reference. If a developer wants to write custom .NET
programming languages, these are the necessary specifications and syntax. The CTS and CLS
define the types and syntaxes that every .NET language needs to embrace. An application may
not expose these features, but it must consider them when communicating through IL.

A big idea in the works


In this article, I’ve covered various aspects of the .NET platform. This includes how the CLR
works to allow programs written in any language to be packaged into assemblies that are
executable on any system supporting CLR. The CLS and the CTS, together with the IL Assembly
Language Programmers Reference and MSIL Instruction Set Specification, define how the IL in
an assembly is generated as well as the process it will go through to be rendered usable by the
CLR. Adoption of these standards will determine if .NET becomes the industrywide default
Microsoft hopes for.

http://articles.techrepublic.com.com/5100-10878_11-1050276.html 6/2/2010
The role of the .NET CLR in creating a global development framework Page 4 of 4

People who read this, also read...


Under the covers of the .NET CLR
I'm confused. . . What is '.NET' anyway?
.NET compilation demystified
Check under the MSIL hood to see how the CLR is running
Store .NET application settings in custom XML .config files

Print/View all Posts


Comments on this article
Question bshoemaker@... | 09/17/02

No such thing Bucky Kaufman (MCSD) | 10/01/02

RE: The role of the .NET CLR in creating a global development framework
abc1@... | 08/13/07
RE: The role of the .NET CLR in creating a global development framework
gopianands@... | 12/14/07
My Updates
My Contacts

Would you like your own dynamic Workspace on TechRepublic?

Take two minutes and set up a TechRepublic member profile.

Would you like your own dynamic Workspace on TechRepublic?

Take two minutes and set up a TechRepublic member profile.

Popular on CBS sites: Fantasy Baseball | iPad | Video Game Reviews | Cell Phones | NFL Draft

About CBS Interactive | Jobs | Advertise | Mobile | Site Map

© 2010 CBS Interactive Inc. All rights reserved. | Privacy Policy (updated) | Terms of Use

http://articles.techrepublic.com.com/5100-10878_11-1050276.html 6/2/2010

Вам также может понравиться