Top .Net Framework Interview Questions

1)  What are the features provided by CLR ?

  • Automatic memory management
  • Exception Handling
  • Standard Types
  • Security

2) Explain Automatic memory management ?

-> is one of the services that the CLR provides during Managed Execution. The CLR’s garbage collector manages the allocation and release of memory for an application. For developers this means that you do not have to write code to perform memory management tasks when you perform memory management tasks when you develop managed applications.

-> When a process is initialized, the runtime reserves a contiguous region of address space for the process. This reserved address space is called the managed heap. The managed heap maintains a pointer to the address where the next object in the heap will be allocated. Initially, this pointer is set to the managed heap’s base address. All reference types are allocated on the managed heap.

-> When an application creates the first reference type, memory is allocated for the type at the base address of the managed heap.

-> Generally .NET is hosted using host process, during debugging .Net creates a process using VSHost.exe which gives the programmer the basic debugging facilities of the IDE and also direct managed memory management of CLR. After deploying the application, the CLR creates the process in the name of its executable and allocates memory directly through Managed Heaps.

-> When CLR is loaded, generally two managed heaps are allocated; one is for small objects (SOH, Small Object Heap) and other for large objects (LOH, Large Object Heap).

-> SOH is assigned for the memory request when size of the memory is less than 83 KBs(85,000 bytes).If its greater than this, it allocates memory from LOH.

-> Generally a process can invoke multiple threads. Now when a process creates new thread, it creates its own stack, but every thread is using the same Heap for memory i.e. Heaps are shared through all threads.

3) Difference between Managed resources and Unmanaged resources ?

Managed Resources
-> are those under the control of the Common Language Runtime (CLR), the runtime environment that executes C# programs.

UnManaged Resources
-> are those outside of the control of the CLR. Unmanaged resources include such things as handlers to windows, files, pens, brushes and other objects the program is manipulating through API calls. e.g. Window, File, DB.

4) What are the Standard Types in .Net framework ?

  1. Value Types
  2. Reference Types
  3. Pointer Types

Value Types
-> Directly stores values.
-> are stored in stack.
-> A value type cannot be null and exists for as long as the object that contains it does.
-> Objects based on value types are destroyed when they go out of scope.
-> int, enum, byte, decimal, double, float, long

Reference Types
-> store a reference to data.
-> are stored in heap.
-> Objects based on reference types are destroyed at an unspecified time after the last reference to them is removed.
-> string, class, interface, object

Pointer Types
-> Only available in unsafe code.

5) What is an Assembly ?

-> An assembly is a container for a set of resources and types.
-> Assemblies can be referenced by other assemblies.
-> In visual studio, an assembly equates to a project.

6) What is an Assembly Manifest ?

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

-> 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.

Each assembly’s manifest performs the following functions.

  • Enumerates the files that make up the assembly.
  • Enumerates other assemblies on which the assembly depends.

Assembly Manifest Contents

-> The assembly name, version number, culture and string name information make up the assembly’s identity.

Information Description
Assembly name A text string specifying the assembly’s name.
Version number A major and minor version number, and a revision and build number. The common language runtime uses these numbers to enforce version policy.
Culture Information on the culture or language the assembly supports. This information should be used only to designate an assembly as a satellite assembly containing culture- or language-specific information. (An assembly with culture information is automatically assumed to be a satellite assembly.)
Strong name information The public key from the publisher if the assembly has been given a strong name.
List of all files in the assembly A hash of each file contained in the assembly and a file name. Note that all files that make up the assembly must be in the same directory as the file containing the assembly manifest.
Type reference information Information used by the runtime to map a type reference to the file that contains its declaration and implementation. This is used for types that are exported from the assembly.
Information on referenced assemblies A list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly’s name, assembly metadata (version, culture, operating system, and so on), and public key, if the assembly is strong named.

7) What is Global Assembly Cache ?

-> Each computer where the CLR is installed has a machine-wide code cache called global assembly cache. The GAC stores assemblies specifically designated to be shared by several applications on the computer.

-> There are two ways to deploy an assembly in to the GAC.
1) Use an installer designated to work with the GAC.
2) Use a developer tool called Gacutil.exe, provided by windows SDK.

Leave a Reply

Your email address will not be published. Required fields are marked *