Showing posts with label .NET Framework. Show all posts
Showing posts with label .NET Framework. Show all posts

Tuesday, 3 May 2011

What is CIL in asp.net ?

Let�s examine CIL code, type metadata, and the assembly manifest in a bit more detail. CIL is a language
that sits above any particular platform-specific instruction set. For example, the following C#
code models a trivial calculator. Don�t concern yourself with the exact syntax for now, but do notice


the format of the Add() method in the Calc class:


// Calc.cs
using System;
namespace CalculatorExample
{
// This class contains the app's entry point.
class Program
{
static void Main()
{
Calc c = new Calc();
int ans = c.Add(10, 84);
Console.WriteLine("10 + 84 is {0}.", ans);
// Wait for user to press the Enter key before shutting down.
Console.ReadLine();
}
}
// The C# calculator.
class Calc
{
public int Add(int x, int y)
{ return x + y; }
}
}
Once you compile this code file using the C# compiler (csc.exe), you end up with a single-file
*.exe assembly that contains a manifest, CIL instructions, and metadata describing each aspect of
the Calc and Program classes.
nNote Chapter 2 examines the details of compiling code using the C# compiler, as well as the use of graphical
IDEs such as Visual Studio, Visual C# Express, and SharpDevelop.
For example, if you were to open this assembly using ildasm.exe (examined a little later in this
chapter), you would find that the Add() method is represented using CIL such as the following:
.method public hidebysig instance int32 Add(int32 x,
int32 y) cil managed
{
// Code size 9 (0x9)
.maxstack 2
.locals init (int32 V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: add
IL_0004: stloc.0
CHAPTER 1 n THE PHILOSOPHY OF .NET 13
IL_0005: br.s IL_0007
IL_0007: ldloc.0
IL_0008: ret
} // end of method Calc::Add
Don�t worry if you are unable to make heads or tails of the resulting CIL for this method�
Chapter 19 will describe the basics of the CIL programming language. The point to concentrate on
is that the C# compiler emits CIL, not platform-specific instructions.
Now, recall that this is true of all .NET-aware compilers. To illustrate, assume you created this
same application using Visual Basic .NET, rather than C#:
' Calc.vb
Imports System
Namespace CalculatorExample
' A VB "Module" is a class that contains only
' static members.
Module Program
Sub Main()
Dim c As New Calc
Dim ans As Integer = c.Add(10, 84)
Console.WriteLine("10 + 84 is {0}.", ans)
Console.ReadLine()
End Sub
End Module
Class Calc
Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Class
End Namespace
If you examine the CIL for the Add() method, you find similar instructions (slightly tweaked by
the VB .NET compiler, vbc.exe):
.method public instance int32 Add(int32 x,
int32 y) cil managed
{
// Code size 8 (0x8)
.maxstack 2
.locals init (int32 V_0)
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: add.ovf
IL_0003: stloc.0
IL_0004: br.s IL_0006
IL_0006: ldloc.0
IL_0007: ret
} // end of method Calc::Add

Asp.net class library

The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third-party components can integrate seamlessly with classes in the .NET Framework.

class library in asp.net


The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third-party components can integrate seamlessly with classes in the .NET Framework.

Common Language Runtime in asp.net

Common Language Runtime (CLR) is a run-time environment that manages the execution of .NET code and provides services like memory management, debugging, security, etc. The CLR is also known as Virtual Execution System (VES). The CLR is a multi-language execution environment. There are currently over 15 compilers being built by Microsoft and other companies that produce code that will execute in the CLR.
The Common Language Runtime (CLR) provides a solid foundation for developers to build various types of applications. Whether you're writing an ASP.Net application , a Windows Forms application, a Web Service, a mobile code application, a distributed application, or an application that combines several of these application models,

CLR provides the following benefits for application developers:

� Vastly simplified development
� Seamless integration of code written in various languages
� Evidence-based security with code identity
� Assembly-based deployment that eliminates DLL Hell
� Side-by-side versioning of reusable components
� Code reuse through implementation inheritance
� Automatic object lifetime management
� Self describing objects

Common Language Specification.

Common Language Specification.

This is a subset of the CTS which all .NET languages are expected to support. The idea is that any program which uses CLS-compliant types can interoperate with any .NET program written in any language.In theory this allows very tight interop between different .NET languages -

 for example allowing a C# class to inherit from a VB class.

Common Type System in asp.net

Common Type System.

  • Asp.net support a multi language . so asp.net provide a Common Type System for all language  (CTS)

  • This is the range of types that the .NET runtime understands, and therefore that .NET applications can use.

  • The CTS is a superset of the CLS.

  •  Note :that not all .NET languages will support all the types in the CTS.

Namespace in asp.net

  • Namespace  is a collection of classes  and  interfaces Namespace is a logical naming scheme for group related types.

  •  A namespace can span multiple assemblies, and an assembly can define multiple namespaces. When the compiler needs the definition for a class type, it tracks through each of the different imported namespaces to the type name and searches each referenced assembly until it is found.

  • Namespaces can be nested. This is very similar to packages in Java as far as scoping is concerned.

What is MSIL?

Intermediate Language. Also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code (of any language) is compiled to MSIL.

When compiling the source code to managed code, the compiler translates the source into Microsoft intermediate language (MSIL). This is a CPU-independent set of instructions that can efficiently be converted to native code. Microsoft intermediate language (MSIL) is a translation used as the output of a number of compilers. It is the input to a just-in-time (JIT) compiler. The Common Language Runtime includes a JIT compiler for the conversion of MSIL to native code.

Before Microsoft Intermediate Language (MSIL) can be executed it, must be converted by the .NET Framework just-in-time (JIT) compiler to native code. This is CPU-specific code that runs on the same computer architecture as the JIT compiler. Rather than using time and memory to convert all of the MSIL in a portable executable (PE) file to native code. It converts the MSIL as needed whilst executing, then caches the resulting native code so its accessible for any subsequent calls.

Thursday, 30 December 2010

What is a Microsoft Intermediate Language?

Intermediate Language. Also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code (of any language) is compiled to MSIL.

When compiling the source code to managed code, the compiler translates the source into Microsoft intermediate language (MSIL). This is a CPU-independent set of instructions that can efficiently be converted to native code. Microsoft intermediate language (MSIL) is a translation used as the output of a number of compilers. It is the input to a just-in-time (JIT) compiler. The Common Language Runtime includes a JIT compiler for the conversion of MSIL to native code.

Before Microsoft Intermediate Language (MSIL) can be executed it, must be converted by the .NET Framework just-in-time (JIT) compiler to native code. This is CPU-specific code that runs on the same computer architecture as the JIT compiler. Rather than using time and memory to convert all of the MSIL in a portable executable (PE) file to native code. It converts the MSIL as needed whilst executing, then caches the resulting native code so its accessible for any subsequent calls.

Friday, 24 December 2010

What is MSIL, ??

MSILis the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. 

 MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

Sunday, 19 December 2010

What is Manifest?

Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. The assembly manifest contains this assembly metadata.

 An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes.

The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.

What is Garbage collection?

Short  :
  1. Garbage collection is a CLR feature which automatically release the  memory from the application .
  2. Programmers forget to release the objects while coding. CLR automatically releases objects when they are no longer referenced and in use. CLR runs on non-deterministic to see the unused objects and cleans them.
  3. The garbage collector (GC) completely absolves the developer from tracking memory usage and knowing when to free memory.
 ------------------------------------------------------------------------------------
Breifly :
Every program uses resources of one sort or another -- memory buffers, network connections, database resources and so on. In fact, in an object-oriented environment, every type identifies some resource available for a program's use. To use any of these resources, memory must be allocated to represent the type.

The steps required to access a resource are as follows:
1. Allocate memory for the type that represents the resource.
2. Initialize the memory to set the initial state of the resource and to make the resource usable.
3. Use the resource by accessing the instance members of the type (repeat as necessary).
4. Tear down the state of the resource to clean up.
5. Free the memory.

What is a CTS / Common Type System ?

Common Type System.

  • Asp.net support a multi language . so asp.net provide a Common Type System for all language  (CTS)

  • This is the range of types that the .NET runtime understands, and therefore that .NET applications can use.

  • The CTS is a superset of the CLS.

  •  Note :that not all .NET languages will support all the types in the CTS.

What is Namespace?

  • Namespace  is a collection of classes  and  interfaces Namespace is a logical naming scheme for group related types.

  •  A namespace can span multiple assemblies, and an assembly can define multiple namespaces. When the compiler needs the definition for a class type, it tracks through each of the different imported namespaces to the type name and searches each referenced assembly until it is found.

  • Namespaces can be nested. This is very similar to packages in Java as far as scoping is concerned.

What is CLR ?

Common Language Runtime (CLR) is a run-time environment that manages the execution of .NET code and provides services like memory management, debugging, security, etc. The CLR is also known as Virtual Execution System (VES). The CLR is a multi-language execution environment. There are currently over 15 compilers being built by Microsoft and other companies that produce code that will execute in the CLR.
The Common Language Runtime (CLR) provides a solid foundation for developers to build various types of applications. Whether you're writing an ASP.Net application , a Windows Forms application, a Web Service, a mobile code application, a distributed application, or an application that combines several of these application models,

CLR provides the following benefits for application developers:

� Vastly simplified development
� Seamless integration of code written in various languages
� Evidence-based security with code identity
� Assembly-based deployment that eliminates DLL Hell
� Side-by-side versioning of reusable components
� Code reuse through implementation inheritance
� Automatic object lifetime management
� Self describing objects

What is CLS?

Common Language Specification.

This is a subset of the CTS which all .NET languages are expected to support. The idea is that any program which uses CLS-compliant types can interoperate with any .NET program written in any language.In theory this allows very tight interop between different .NET languages -

 for example allowing a C# class to inherit from a VB class.

.NET Framework Class Library

The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third-party components can integrate seamlessly with classes in the .NET Framework.

Wednesday, 15 December 2010

Common Language Runtime in asp.net

CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that converts a MSIL code into the host machine language code, which is then executed appropriately. The CLR is the execution engine for .NET Framework applications.

It provides a number of services, including:
? Code management (loading and execution)
? Application memory isolation
? Verification of type safety
? Conversion of IL to native code.
? Access to metadata (enhanced type information)
? Managing memory for managed objects
? Enforcement of code access security
? Exception handling, including cross-language exceptions
? Interoperation between managed code, COM objects, and pre-existing DLL's (unmanaged code and data)
? Automation of object layout
? Support for developer services (profiling, debugging, and so on).

Monday, 30 November 2009

over view of Common Language Runtime (CLR)

In addition to the CTS and CLS specifications, the final TLA (three-letter abbreviation) to contend
with at the moment is the CLR. Programmatically speaking, the term runtime can be understood as
a collection of external services that are required to execute a given compiled unit of code. For
example, when developers make use of the MFC to create a new application, they are aware that
their program requires the MFC runtime library (i.e., mfc42.dll). Other popular languages also
have a corresponding runtime. VB6 programmers are also tied to a runtime module or two (e.g.,
msvbvm60.dll). Java developers are tied to the Java Virtual Machine (JVM), and so forth.
The .NET platformoffers yet another runtime system. The key difference between the .NET
runtime and the various other runtimes I just mentioned is the fact that the .NET runtime provides
a single well-defined runtime layer that is shared by all languages and platforms that are .NETaware.
The crux of the CLR is physically represented by a library named mscoree.dll (a.k.a. the Common
Object Runtime Execution Engine). When an assembly is referenced for use, mscoree.dll is
loaded automatically, which in turn loads the required assembly into memory. The runtime engine
is responsible for a number of tasks. First and foremost, it is the entity in charge of resolving the
location of an assembly and finding the requested type within the binary by reading the contained
metadata. The CLR then lays out the type in memory, compiles the associated CIL into platformspecific
instructions, performs any necessary security checks, and then executes the code in
question.
In addition to loading your custom assemblies and creating your custom types, the CLR will
also interact with the types contained within the .NET base class libraries when required. Although
the entire base class library has been broken into a number of discrete assemblies, the key assembly
is mscorlib.dll. mscorlib.dll contains a large number of core types that encapsulate a wide variety
of common programming tasks as well as the core data types used by all .NET languages. When you
build .NET solutions, you automatically have access to this particular assembly.
Figure 1-4 illustrates the workflow that takes place between your source code (which is making
use of base class library types), a given .NET compiler, and the .NET execution engine.

Over view of Common Language Specification (CLS)

As you are aware, different languages express the same programming constructs in unique, language-
specific terms. For example, in C# you denote string concatenation using the plus operator
(+), while in VB .NET you typically make use of the ampersand (&). Even when two distinct languages
express the same programmatic idiom (e.g., a function with no return value), the chances
are very good that the syntax will appear quite different on the surface:
// C# method returning nothing.
public void MyMethod()
{
// Some interesting code...
}

' VB method returning nothing.
Public Sub MyMethod()
' Some interesting code...
End Sub
As you have already seen, these minor syntactic variations are inconsequential in the eyes of
the .NET runtime, given that the respective compilers (csc.exe or vbc.exe, in this case) emit a similar
set of CIL instructions. However, languages can also differ with regard to their overall level of
functionality. For example, a .NET language may or may not have a keyword to represent unsigned
data, and may or may not support pointer types. Given these possible variations, it would be ideal
to have a baseline to which all .NET-aware languages are expected to conform.
The CLS is a set of rules that describe in vivid detail the minimal and complete set of features a
given .NET-aware compiler must support to produce code that can be hosted by the CLR, while at
the same time be accessed in a uniform manner by all languages that target the .NET platform. In
many ways, the CLS can be viewed as a subset of the full functionality defined by the CTS.
The CLS is ultimately a set of rules that compiler builders must conform to, if they intend their
products to function seamlessly within the .NET universe. Each rule is assigned a simple name (e.g.,
�CLS Rule 6�) and describes how this rule affects those who build the compilers as well as those
who (in some way) interact with them. The cr�me de la cr�me of the CLS is the mighty Rule 1:
� Rule 1: CLS rules apply only to those parts of a type that are exposed outside the defining
assembly.
Given this rule, you can (correctly) infer that the remaining rules of the CLS do not apply to the
logic used to build the inner workings of a .NET type. The only aspects of a type that must conform
to the CLS are the member definitions themselves (i.e., naming conventions, parameters, and
return types). The implementation logic for a member may use any number of non-CLS techniques,
as the outside world won�t know the difference.
To illustrate, the following Add() method is not CLS-compliant, as the parameters and return
values make use of unsigned data (which is not a requirement of the CLS):
class Calc
{
// Exposed unsigned data is not CLS compliant!
public ulong Add(ulong x, ulong y)
{ return x + y;}
}
However, if you were to simply make use of unsigned data internally as follows:
class Calc
{
public int Add(int x, int y)
{
// As this ulong variable is only used internally,
// we are still CLS compliant.
ulong temp = 0;
...
return x + y;
}
}
you have still conformed to the rules of the CLS, and can rest assured that all .NET languages are
able to invoke the Add() method.
Of course, in addition to Rule 1, the CLS defines numerous other rules. For example, the
CLS describes how a given language must represent text strings, how enumerations should be
represented internally (the base type used for storage), how to define static members, and so forth.

Luckily, you don�t have to commit these rules to memory to be a proficient .NET developer. Again,
by and large, an intimate understanding of the CTS and CLS specifications is only of interest to
tool/compiler builders.