Common Language Runtime
Question: What services does the .NET common language
runtime provide on top of the services that are offered
by Windows? What are the benefits of these services?
Answer: The common language runtime (CLR) offers the
following services on top of the Windows operating system
(or an alternative operating system):
-
Language interoperability. This means binary
compatibility and seamless cooperation between programs
written in any of more than 20 .NET languages. All .NET
programs are translated to CIL code, which is compiled
to machine code at load time (just in time). The common
type system (CTS) defines the types that are supported
by the CLR. A subset of these types is called the
common language specification (CLS). These are the
types that have to be supported by all languages that
wish to cooperate with others under .NET. The CLS also
makes sure that subclassing, threading and exception
handling work the same way in all of these languages
and can thus be transparently used across all languages.
-
Garbage collection. The CLR has a garbage collector
that makes sure that all dynamically allocated objects are
automatically reclaimed as soon as they are not referenced
any more. This avoids a lot of common programming errors
such as deallocation an object that is still in use or
forgetting to deallocate an unused object.
-
Versioning. .NET programs come in components that
are either stored in EXE files or in DLL files. These
components are self-contained, i.e. they contain information
about all referenced components as well as type information,
which can be used for reflection. There is no need for
making registry entries for assemblies, because they
contain all the information that is necessary to load
and execute them. Deployment can therefore be as simple
as copying the DLL and EXE files to the disk.
An assembly is not only referenced by its name but also by
its version number. The compiler stores the version number
of referenced assemblies in the object file of the client
program. When this client is loaded, the loader searches
for the required assemblies with the version numbers that
were seen at compilation time. This guarantees that the
type checks of the compiler are still valid at run time.
Components with the same name but with different version
numbers can co-exist on the disk as well as in main memory.
Installing new software can therefore never destroy
identically named DLLs of some other application. This
is called the end of the DLL hell.
-
Security. When an assembly is loaded it is first
verified to ensure that its object code has not been
manipulated to break the type rules. Assemblies can also
be signed using public key encryption. This guarantees
that an assembly really comes from a certain trusted
institution instead of from a hacker. For every assembly
as well as for every zone or publisher the administrator
can define code-based as well as role-based rights. This
can be used to run untrusted applications in a sandbox
instead on an open machine.
|