Ans.When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be run, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture.
When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type's members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.
-------------------------------------------------------------------------------2 What is CLR?
Ans. Common Language Runtime(CLR) is the execution engine of .net framework. It provides following benefits.
* Performance improvements.
* The ability to easily use components developed in other languages.
* Extensible types provided by a class library.
* New language features such as inheritance, interfaces, and overloading for object-oriented programming; support for explicit free threading that allows creation of multithreaded, scalable applications; support for structured exception handling and custom attributes.
*Cross-language integration, especially cross-language inheritance.
*Garbage collection, which manages object lifetime so that reference counting is unnecessary.
*Self-describing objects, which make using Interface Definition Language (IDL) unnecessary.
*The ability to compile once and run on any CPU and operating system that supports the runtime.
*Structured Error Handling
-----------------------------------------------------------------------------------------
3. What is CTS?
Ans. The Common Type System in the CLR is the component that defines how data types are declared and used. The fact that the CLR can support cross-language integration to the level it does is largely because of the Common Type System. In the past, each language used its own data types and managed data in its own way. This made it very difficult for applications developed in different languages to communicate, because no standard way existed in which to pass data between them.
The Common Type System ensures that all .NET applications use the same data types, provides for self-describing type information (called metadata), and controls all the data manipulation mechanisms so that data is handled (stored and processed) in the same way among all .NET applications. This allows data (including objects) to be treated the same way in all .NET languages.
-----------------------------------------------------------------------------------------
4 What is CLS(Common Language Specification)?
Ans. To fully interact with other objects regardless of the language they were implemented in, objects must expose to callers only those features that are common to all the languages they must interoperate with. For this reason, the Common Language Specification (CLS), which is a set of basic language features needed by many applications, has been defined. The CLS rules define a subset of the common type system; that is, all the rules that apply to the common type system apply to the CLS, except where stricter rules are defined in the CLS. The CLS helps enhance and ensure language interoperability by defining a set of features that developers can rely on to be available in a wide variety of languages. The CLS also establishes requirements for CLS compliance; these help you determine whether your managed code conforms to the CLS and to what extent a given tool supports the development of managed code that uses CLS features
-----------------------------------------------------------------------------------------
5. What is Managed Code?
Ans. Managed code is code that has its execution managed by the .NET Framework Common Language Runtime. It refers to a contract of cooperation between natively executing code and the runtime. This contract specifies that at any point of execution, the runtime may stop an executing CPU and retrieve information specific to the current CPU instruction address. Information that must be query-able generally pertains to runtime state, such as register or stack memory contents.
-----------------------------------------------------------------------------------------
6. What is an Assembly?
Ans. An assembly is a package of code and metadata. When you deploy a set of classes in an assembly, you are deploying the classes as a unit; and those classes share the same level of version control, security information, and activation requirements. Think of an assembly as a "logical DLL." If you're familiar with Microsoft Transaction Server or COM+, you can think of an assembly as the .NET equivalent of a package.
It is an Output Unit. It is a unit of Deployment & a unit of versioning. Assemblies contain MSIL code.Assemblies are Self-Describing. [e.g. metadata,manifest]An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.
.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 different programming languages are just perfect for creating certain kinds of applications. For example, COBOL stands for Common Business-Oriented Language because it is tailor-made for creating business applications. However, it is 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.
There is a hierarchy to the structure of .NET code. That hierarchy is Assembly -> Module -> Type -> Method. Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.
Assemblies also allow Side-by-Side execution, 2 versions of same assembly can be used at the same time.
----------------------------------------------------------------------------------------
7. What are different types of Assembly?
Ans. There are two types of assemblies: private assemblies and global assemblies. When you build your assembly, you don't need to specify whether you want to build a private or a global assembly. The difference is apparent when you deploy your assembly. With a private assembly, you make your code available to a single application. Your assembly is packaged as a DLL, and is installed into the same directory as the application using it. With a deployment of a private assembly, the only application that can use your code is the executable that lives in the same directory as your assembly. If you want to share your code among many applications, you might want to consider deploying your code as a global assembly. Global assemblies can be used by any .NET application on the system, regardless of the directory in which it is installed. Microsoft ships assemblies as a part of the .NET Framework, and each of the Microsoft assemblies is installed as a global assembly. The .NET Framework contains a list of global assemblies in a facility called the global assembly cache, and the .NET Microsoft Framework SDK includes utilities to both install and remove assemblies from the global assembly cache.
---------------------------------------------------------------------------------------
8. What is Namespace?
Ans. Namespaces organize classes under a named group, and the namespace name can be used to help distinguish between two classes with the same name.
---------------------------------------------------------------------------------------
9. What is difference between Namespace and Assembly?
Ans. Namespace: It is a Collection of names wherein each name is Unique.They form the logical boundary for a Group of classes.Namespace must be specified in Project-Properties.Assembly: It is an Output Unit. It is a unit of Deployment & a unit of versioning. Assemblies contain MSIL code.Assemblies are Self-Describing. [e.g. metadata,manifest]An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.
.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 different programming languages are just perfect for creating certain kinds of applications. For example, COBOL stands for Common Business-Oriented Language because it is tailor-made for creating business applications. However, it is 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.
There is a hierarchy to the structure of .NET code. That hierarchy is Assembly -> Module -> Type -> Method. Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.
Assemblies also allow Side-by-Side execution, 2 versions of same assembly can be used at the same time.
----------------------------------------------------------------------------------------
10. If you want to view a Assembly how to you go about it (What is ILDASM ?) ?
Ans. It allows user to see the pseudo assembly language for .NET". IL disassmeber tool shows not only namespace but also types including their interfaces. As its name suggests, it is an intermediate language, so it has its own specification. Users can also write programs using this intermediate language, its very similar to assembly language of the old days.
----------------------------------------------------------------------------------------
11.What is Manifest?
Ans.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.
It conents -
Assembly Name
Version Number
Culture
Strong name information
List of all files in Assembly
Type reference information
Info. on referenced assemblies
----------------------------------------------------------------------------------------
12. Where is version information stored of a assembly ?
Ans. All versioning of assemblies that use the common language runtime is done at the assembly level. The specific version of an assembly and the versions of dependent assemblies are recorded in the assembly's manifest. The default version policy for the runtime is that applications run only with the versions they were built and tested with, unless overridden by explicit version policy in configuration files (the application configuration file, the publisher policy file, and the computer's administrator configuration file).
Note Versioning is done only on assemblies with strong names.
-----------------------------------------------------------------------------------------
13. Is versioning applicable to private assemblies?
Ans. No.
-----------------------------------------------------------------------------------------
15.What is concept of strong names ? / How do we generate strong names or what is the process of generating stong names , What is use of SN.EXE , How do we apply strong names to assembly ? , How do you sign an assembly ?
Ans.Assemblies can be assigned a cryptographic signature, called a strong name, which provides name uniqueness for the assembly and prevents someone from taking over the name of your assembly (name spoofing). If you are deploying an assembly that will be shared among many applications on the same machine, it must have a strong name. Even if you only use the assembly within your application, using a strong name ensures that the correct version of the assembly gets loaded
The first step in building an assembly with a strong name is to obtain a cryptographic key pair. The .NET Framework SDK includes a Strong Name tool (Sn.exe) that can be used to generate a key pair. The key pair that is generated by the Strong Name tool can be kept in a file or you can store it in your local machine's Crytographic Service Provider (CSP). The following command uses the Strong Name tool to generate a new key pair and store it in a file called TestKey.snk:
sn -k Testkey.snk
Once you have obtained the key pair, you need to add the proper custom attribute to your source in order for the compiler to emit the assembly with a strong name. Choosing the correct attribute depends on whether the key pair used for the signing is contained in a file or in a key container within the CSP. For keys stored in a file, use System.Reflection.AssemblyKeyFileAttribute. For keys stored in the CSP use System.Reflection.AssemblyKeyNameAttribute.
The following example uses AssemblyKeyFileAttribute to specify the name of the file containing the key pair. In Visual Basic, the assembly level attributes must be the first statements in the file.
Imports System
Imports System.Reflection
-----------------------------------------------------------------------------------------
14. What is GAC ? / What are situations when you register .NET assembly in GAC ?
Ans. Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.
You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.
-----------------------------------------------------------------------------------------
16. How to add and remove a assembly from GAC?
Ans. Installing Assemblies
To install an assembly using the shell extension simply drag and drop the file containing the assembly's manifest into the global assembly cache directory. To install an assembly using the Global Assembly Cache tool, use the /i option:
gacutil /i math.dll
Uninstalling Assemblies
To delete an assembly with the shell extension, right click on it and select Delete. The /u option of the Global Assembly Cache tool can also be used:
gacutil /u math,ver=1.0.0.0
-----------------------------------------------------------------------------------------
17. What is Delay signing ?
Ans. The .NET Framework offers delay signing, which effectively splits the process of assigning the strong name into two steps:
1. At build time, the public key is given to the compiler so it can be recorded in the PublicKey field in the assembly manifest. Also, space is reserved in the file for the signature, although the actual signature is not generated at this time.
2. At a later time, the the actual signature is generated and stored in the file. Signature generation is done with the -R switch to the Strong Named tool (Sn.exe).
When you include the System.Reflection.AssemblyDelaySignAttribute in your source code, it indicates to the compiler that the assembly needs to be created with delay signing. You also need to include the public key, using AssemblyKeyFileAttribute. Typically, the signing entity will use the SN -k to generate a key pair and store it in a file. Next, it pulls the public key out of the file using SN -p. The public key can then be given out, with the private key still secret.
sn -k Testkey.snk
sn -p Testkey.snk TestPublicKey.snk
The following example uses AssemblyKeyFileAttribute and AssemblyDelaySignAttribute to create a delay signed assembly. In Visual Basic, the assembly level attributes must be the first statements in the file.
Imports System
Imports System.Reflection
-----------------------------------------------------------------------------------------
18. What is garbage collection?
Ans. The .NET Framework's garbage collector manages the allocation and release of memory for your application. Each time you use the new operator to create an object, the runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.
------------------------------------------------------------------------------------------
19. Can we force garbage collector to run ?
Ans. First, you should be aware that the garbage collector works automatically, whether you request it to or not. Secondly, you cannot force the garbage collector to run.
That said, you can request the garbage collector to perform work, by invoking the System.gc() method. Once working, you may experience a short pause while the garbage collector does its work. That means you should do it at an appropriate time, such as before a big task or when the GUI is idle and waiting for input.
-------------------------------------------------------------------------------------------
20. What are Value types and Reference types ?
Ans. A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.
Value Types
Value types include the following:
All numeric data types
Boolean, Char, and Date
All structures, even if their members are reference types
Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong
Reference Types
Reference types include the following:
String
All arrays, even if their elements are value types
Class types, such as