Dot Net Questions: Explain The Concepts of CTS and CLS (Common Language Specification)
Dot Net Questions: Explain The Concepts of CTS and CLS (Common Language Specification)
From the source code, the compiler generates Microsoft Intermediate Language (MSIL) which is further used for
the creation of an EXE or DLL. The CLR processes these at runtime. Thus, compiling is the process of
generating this MSIL.
Compilation can be done with Debug or Release configuration. The difference between these two is that in the
debug configuration, only an assembly is generated without optimization. However, in release complete
optimization is performed without debug symbols
a. Class Loader: is an abstract class. Its purpose is to tell JVM in what manner a class is to be loaded at runtime.
b. MSIL: Microsoft Intermediate Language is considered to be the lowest form of human readable language. It is
CPU independent and includes instructions of how to load, store, initialize objects. JIT converts this MSIL into
native code which is dependent on the CPU.
d. Garbage Collector: The .NET garbage collector enables high-speed allocation and release of memory for the
objects in managed code. Its main aim is proper memory management.
f. Type Checker: It enforces the constraints of types. It enforces strictness in type checking.
i. Base class library: It provides all the types that an application need at runtime.
j. Exception manager: Handles all the exception for an application during runtime.
CTS
When different languages are integrated and want to communicate, it is certain that the languages have their
own data types and different declaration styles. CTS define how these different variables are declared and used
in run time. E.g. VB offers an Integer data type while C++ offers long data type. Using CTS, these data types are
converted to System32 which itself a data type of CLS.
CLS
Any language(s) that intend to use the Common Language Infrastructure needs to communicate with other CLS-
Compliant language. This communication is based on set of rules laid by CLS. These rules define a subset of
CTS.
The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the
sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be
overridden. However, its usage is advised for making the code meaningful.
The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify
a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract
method directly.
An abstract virtual method means that the definition of the method needs to be given in the derived class.
Often there is a need for different languages to communicate with each other at run time. For e.g. A class may be
written in one language and its derived class may be written in a different language. Common Language Runtime
is a run time environment for .NET. These different languages are integrated and can communicate easily
because language compilers and tools that target the runtime use a common type system defined by the runtime.
Operator overloading is the most evident example of Polymorphism. In operator overloading, an operator is
‘overloaded’ or made to perform additional functions in addition to what it actually does. For e.g. we can overload
the “+” operator to add two complex numbers or two imaginary numbers.
Example:
An employee object is associated with manager object.
Aggregation is “a part of” relationship.
Example:
A student object is a part of College object.
Inheritance is a “is a “relationship where one or more classes are derived from a base class. The derived class
has the base class plus its own characteristics.
Example:
French_Student class can be a derived class of student class.
a. ServiceBase
a. OnStart
b. OnPause
c. OnStop
d. OnContinue
e. OnShutdown
f. OnCustomCommand
g. OnPowerEvent
b. ServiceProcessInstaller
c. ServiceInstaller
d. ServiceController
b. Paused: The service cannot perform anything beyond till the paused state is changed.
c. Stopped: The application based on this service will not work until the service is started once again.
Win32OwnProcess
Win32ShareProcess
a. Win32OwnProcess: It is a Win32 process that can be started by the Service Controller. This type of Win32
service runs in a process by itself.
b. Win32ShareProcess: It is a Win32 service that allows sharing of processes with other Win32 services.
e.g.:
Imperative security:security requests are made in the form of lines of code within a method body.Basically an
instance of permission object is created that needs to be invoked.
e.g.:
Side by side execution refers to running/execution of different versions of the same assembly at the same time
on the same machine. It gives us more control over the versioning of the assembly. When you strong name an
assembly, version number becomes a part of its identity, and thus we can register different version of the same
assembly in the GAC and execute them side by side.
One should create a resource only assembly if you need to update the resources frequently without recompiling
the whole solution.
Use ResourceManager class to retrieve resources that exist in an assembly. Steps to do so are:
e.g.:
Managed code not always is slower than unmanaged code. In managed code, the CLR does some optimization
for the way loops, subroutines should run and what is the best way to execute it.
Managed Code:-
Managed code is code written in one of over twenty high-level programming languages that are available for use
with the Microsoft® .NET Framework, including C#, J#, Microsoft Visual Basic® .NET, Microsoft JScript® .NET,
and C++. All of these languages share a unified set of class libraries and can be encoded into an Intermediate
Language (IL). A runtime-aware compiler compiles the IL into native executable code within a managed
execution environment that ensures type safety, array bound and index checking, exception handling, and
garbage collection.
By using managed code and compiling in this managed execution environment, you can avoid many typical
programming mistakes that lead to security holes and unstable applications. Also, many unproductive
programming tasks are automatically taken care of, such as type safety checking, memory management, and
destruction of unneeded objects. You can therefore focus on the business logic of your applications and write
them using fewer lines of code. The result is shorter development time and more secure and stable applications.
UnManaged Code
The Microsoft .NET Framework promotes interaction with COM components, COM+ services, external type
libraries, and many operating system services. Data types, method signatures, and error-handling mechanisms
vary between managed and unmanaged object models. To simplify interoperation between .NET Framework
components and unmanaged code and to ease the migration path, the common language runtime conceals from
both clients and servers the differences in these object models.
Code executing under the control of the runtime is called managed code. Conversely, code that runs outside the
runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are
examples of unmanaged code.
--