Basics of
Basics of
The .NET Framework is a new and revolutionary platform created by Microsoft for
developing applications.
Architecture of CLR
Unmanaged Code
The code, which is developed outside .NET, Framework is known as unmanaged
code.
Applications that do not run under the control of the CLR are said to be unmanaged,
and certain languages such as C++ can be used to write such applications, which,
for example, access low - level functions of the operating system. Background
compatibility with code of VB, ASP and COM are examples of unmanaged code.
What is an IL?
Twist: - What is MSIL or CIL, What is JIT?
(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language)
or CIL
(Common Intermediate Language). All .NET source code is compiled to IL. IL is then
converted
to machine code at the point where the software is installed, or at run-time by a
Just-In-Time
(JIT) compiler.
What is a CLR?
Full form of CLR is Common Language Runtime and it forms the heart of the .NET
framework.
All Languages have runtime and it is the responsibility of the runtime to take care of
the code
execution of the program. For example, VC++ has MSCRT40.DLL, VB6 has
MSVBVM60.DLL,
and Java has Java Virtual Machine etc. Similarly, .NET has CLR. Following are the
responsibilities of CLR
Garbage Collection: - CLR automatically manages memory thus eliminating
memory leaks. When objects are not referred, GC automatically releases those
memories thus providing efficient memory management.
Code Access Security: - CAS grants rights to program depending on the security
configuration of the machine. Example the program has rights to edit or create a
new file but the security configuration of machine does not allow the program to
delete a file. CAS will take care that the code runs under the environment of
machines security configuration.
Code Verification: - This ensures proper code execution and type safety while
the
code runs. It prevents the source code to perform illegal operation such as
accessing
invalid memory locations etc.
IL (Intermediate language)-to-native translators and optimizers:- CLR
uses
JIT, compiles the IL code to machine code, and then executes. CLR also determines
depending on platform what is optimized way of running the IL code.
What is CTS?
In order that two language communicate smoothly CLR has CTS (Common Type
System).Example in VB you have Integer and in C++ you have long these
datatypes are not
compatible so the interfacing between them is very complicated. In order that these
two different
languages communicate Microsoft introduced Common Type System. So Integer
data type in
VB6 and int data type in C++ will convert it to System.int32, which is data type of
CTS. CLS,
which is covered in the coming question, is subset of CTS.
Note: If you have undergone COM programming period interfacing VB6
application with VC++ application was a real pain as the datatype of
both languages did not have a common ground where they can come and
interface, by having CTS interfacing is smooth.
What is a CLS (Common Language Specification)?
This is a subset of the CTS, which all .NET languages are expected to support. It was
always a
dream of Microsoft to unite all different languages in to one umbrella and CLS is
one-step
towards that. Microsoft has defined CLS, which are nothing but guidelines, that
language should
follow so that it can communicate with other .NET languages in a seamless manner.
What is a Managed Code?
Managed code runs inside the environment of CLR i.e. .NET runtime. In short, all IL
are
managed code. However, if you are using some third party software example VB6 or
VC++
component they are unmanaged code, as .NET runtime (CLR) does not have control
over the
source code execution of these languages.
What is a Assembly?
Assembly is unit of deployment like EXE or a DLL.
An assembly consists of one or more files (dlls, exes, html files etc.), and
represents a group of resources, type definitions, and implementations of those
types. An assembly may also contain references to other assemblies. These
resources, types and references are described in a block of data called a manifest.
The manifest is part of the assembly, thus making the assembly self-describing.
In shared assembly deployment, an assembly is installed in the Global Assembly
Cache (or GAC). The GAC contains shared assemblies that are globally accessible
to all .NET applications on the machine.
(A) What are the different types of Assembly?
There are two types of assembly Private and Public assembly. A private assembly is
normally
used by a single application, and is stored in the application's directory, or a subdirectory
beneath. A shared assembly is normally stored in the global assembly cache, which
is a repository
of assemblies maintained by the .NET runtime. Shared assemblies are usually
libraries of code,
which many applications will find useful, e.g. Crystal report classes that will be used
by all
application for Reports.
(B) What is NameSpace?
Namespace has two basic functionality: NameSpace Logically group types, example System.Web.UI logically groups UI
related features.
In Object Oriented world, many times it is possible that programmers will use the
same class name. Qualifying NameSpace with class name can avoid this collision.
(B) What is Difference between NameSpace and Assembly?
Following are the differences between namespace and assembly:
Assembly is physical grouping of logical units, Namespace, logically groups
classes.
Namespace can span multiple assembly.
Where is version information stored of an assembly?
Version information is stored in assembly inside the manifest.
What is GAC?
GAC (Global Assembly Cache) is where all shared .NET assembly reside. GAC is used
in the
following situations: If the application has to be shared among several application.
If the assembly has some special security, requirements like only administrators
can
remove the assembly. If the assembly is private then a simple delete of assembly
the assembly file will remove the assembly.
Note:- Registering .NET assembly in GAC can lead to the old problem of
DLL hell, where COM version was stored in central registry. So GAC
should be used when absolutely necessary.