Explain CLR in brief.
Answer
CLR stands for Common Language Runtime.
The CLR is a development platform. It provides a runtime, defines functionality in some libraries, and supports a set of programming languages. The CLR provides a runtime so that the softwares can utilize its services. The CLR Base Class Library allows interaction with the runtime. The CLR supports various programming languages, several standards and is itself been submitted as an open standard.
Describe how a .Net application is compiled and executed.
Answer
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.
The way you do it in .Net is as follows:
Right-click and select Build / Ctrl-Shift-B / Build menu, Build command
F5 - compile and run the application.
Ctrl+F5 - compile and run the application without debugging.
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.
Describe the parts of assembly.
Answer
An assembly is a partially compiled code library. In .NET, an assembly is a portable executable and can be an EXE (process assembly) or a DLL (library assembly). An assembly can consist of one or more files or modules in various languages. It is used in deployment, versioning and security.
Explain the .Net Framework.
Answer - The .Net framework allows infrastructural services to all the applications developed in .net compliant language. It is an engine that provides runtime services using its component like Common Runtime Language. It consists of two main components such as Common Language Runtime and Framework Class Library.
Describe the .Net Framework Architecture.
Answer - The .Net Framework has two main components:
.Net Framework Class Library: It provides common types such as data types and object types that can be shared by all .Net compliant language.
The Common language Runtime: It provides services like code execution, type safety, security, thread management, interoperability services.
What are the components of the .Net Framework?
Answer - Class Loader, Compiler, Garbage Collection, Type checker, Debug engine, Exception Manager, Security engine, Thread manager, COM Marshallar, Class Library.
Explain the role of assembly in the .Net Framework.
Answer - .Net Framework keeps executable code or DLL in the form of assembly. .Net Framework maintains multiple versions of the application in the system through assembly. The assemblies have MSIL code and manifest that contains metadata. The metadata contains version information of the assembly.
Describe the GAC in the .Net Framework.
Answer - .Net Framework provides Global Assembly cache, a machine-wide cache. It stores shared assemblies that can be accessed by multiple languages
Define .Net Assembly.
Answer - It is a primary unit of deployment in a Microsoft .NET Framework application. It is called as building block of an application which provides all required execution information to common language runtime.
An assembly perform following functions:
It contains IL code that gets executed by common language runtime.
It forms a security boundary.
An assembly is the unit at which permissions are requested and granted.
It ensures type safety by establishing name scope for types at the runtime.
It contains version information.
It allows side-by-side execution of multiple versions of same assembly.
Assemblies can be static or dynamic.
Static assemblies are created when the program is compiled using .Net compiler. It exists as PE file either in .exe or .dll. However, dynamic assemblies are created at runtime and run from the memory without getting saved on the disk.
What does an assembly contain?
Answer - An assembly contains following information:
Assembly manifest: Information about the assembly.
Type metadata: Information about the types.
IL Code
Resource files.
An assembly manifest contains the following information:
Identity of the assembly
Types and resources
Files
Security permissions
Define private assembly and a shared assembly.
Answer - A private assembly is stored in the application’s directory and used by a single application. A share assembly can be used by multiple applications and is stored in the Global assembly cache, a repository of assemblies maintained by the .Net Framework.
What are Satellite Assemblies?
Answer - Satellite assemblies provide an application the multilingual support. Satellite assemblies contain alternate sets of resources to be used in the application for different cultures.
What do you understand by side-by-site execution of assembly?
Answer - This means multiple version of same assembly to run on the same computer. This feature enables to deploy multiple versions of the component.
How do you create a resource-only assembly?
Answer - Resources are nonexecutable data in an application and the data can be updated without recompiling application. Resource assemblies can be created as follows:
Add resource files to an empty project.
Built the project.
The resource will get compiled into assembly.
Explain how to retrieve resources using ResourceManager class.
Answer - ResourceManager class is used to retrieve resources at run time.
Create a ResourceManager with resource file name and the resource assembly as parameters.
After having created, you can use ResourceManager.GetString method to retrieve a string.
Use the ResourceManager.GetObject method to retrieve images and objects from a resource file.
Define Strong Name. How do you apply a strong name to assembly?
Answer - A strong name means generating public key in order to provide unique name to the assembly.
The name is used to provide global name to the assembly and allows it to be shared amongst several different applications.
The key generated include assembly's name, the version number, the developer's identity, and a hash number.
The developer's identity identifies the author of the assembly.
The hash checks if the assembly is tempered since it is created.
The key pair that defines the strong name is created using the Strong Name utility, Sn.exe.
To sign an assembly with a strong name
Create Key pair using the Strong Name utility, Sn.exe.
Open the AssemblyInfo file of your project.
Use the AssemblyKeyFileAttribute to specify the path to the key file for your project.
Build your assembly. The strong name will be generated and signed to the assembly.
Define Global Assembly Cache.
Answer - Global Assembly Cache is the place holder for shared assembly. If an assembly is installed to the Global Assembly Cache, the assembly can be accessed by multiple applications. In order to install an assembly to the GAC, the assembly must have to be signed with strong name.
How do you install assembly to the Global Assembly Cache?
Answer - Followings are the steps to install assembly to the GAC.
Sign assembly with a strong name using strong name utility, sn.exe.
Open the AssemblyInfo file for your project.
Use the AssemblyKeyFileAttribute to specify the path to the key file for your project.
Build your assembly. Install the assembly to GAC by using gacutil utility e.g. gacutil -i abc.dll
What is code security? What are the types?
Answer - .Framework provides the security features to secure code from unauthorized users and unauthorized uses.
There are two types of code security:
Role based security: This authorizes user.
Code access security: This protects system resources from unauthorized calls.
Define Principal object.
Answer - The Principal object represents authenticated users. It contains information about user’s identity and role. You have PrincipalPermission object in .Framework that specifies user and its role. It has Demand method that checks the current user or Principal against the name and role specified in the PrincipalPermission.
Define declarative and imperative security.
Answer - Security checks can be applied imperatively or declaratively. Declarative security is applied by associating attribute declarations that specify a security action with classes or methods. Imperative security is applied by calling the appropriate methods of a Permission object that represents the Principal (for role-based security) or system resource (for code access security).
Define role-based security.
Answer - Role-based security is to verify the role and/or identity of the current Principal object.
Explain code access security.
Answer - Code access security protects code from unauthorized calls. You can prevent access to the system resources using Permission object. The permission object specifies user and its role. The demand method of permission object checks if specified user and role matches with the current user.
What is Code group?
Answer - Code groups represent collections of code and each code group has an associated set of permissions.
Define the use of Caspol.exe.
Answer - It is DOS command to view and alter code access security policy.
Describe how exceptions are handled by the CLR?
Answer
Usually the exceptions that occur in the try are caught in the catch block. The finally is used to do all the cleaning up work. But exceptions can occur even in the finally block. By using CLR, the exception are caught even in the finally block. Also when an exception is thrown, the CLR looks for an appropriate catch filter that can handle the exception and then it executes the finally block before terminating the execution on the catch filter.
How to throw a custom exception?
Answer
The usual try - catch - finally - ent try format has to be followed. However, in this case, instead of using the preset exceptions from the System.Exception, you define your OwnException class and inherit Exception or ApplicationException class.
You need to define three constructors in your OwnException Class: One without parameters, other with String parameter for error message and the last one has to have one parameter as a String and other as an Inner exception object.
Example:
class OwnException : ApplicationException
{
public OwnException() : base() {}
public OwnException(string s) : base(s) {}
public OwnException(string s, Exception ae) : base(s, ae) {}
}
Explain Form level validation and Field level Validation.
Field-level validation provides immediate validation of the input given by the user. The events associated with field-level validation are KeyDown, KeyPress, textchange, etc.
In form-level validation the validation step is done after the filling up of the form is done. It’s usually when the user submits the forms.
.NET garbage collection - August 25, 2008 at 18:00 PM by Amit Satpute
What is garbage collection?
Answer
The applications created acquire memory. Memory management includes deallocating this acquired resources and acquiring them. This is done by garbage collector and this concept of automatically reclaiming the memory is called Garbage Collection.
Is it possible to force garbage collection to run?
Answer
Yes, it is possible to force Garbage Colletcion . The way to do it is by using GC.Collect().
However, it is also necessary to run the finalizers of the objects that need to be deallocated. So, it is necessary to use GC.WaitForPendingFinalizers() along with GC.Collect() so that the finalizers threads are not executed separately.
Define Dispose().
Answer
It is a method for releasing resources that an object acquires. The Dispose method is called by the destructor.
Explain how garbage collection manages reclamation of unused memory in .NET.
CLR performs garbage collection on small objects and large objects separately. It maintains separate heaps for these two types of objects. Large Objects are maintained in LO
Heap and small objects are kept in multiple heaps which are compacted regularly.
It uses the JIT compiler which provides it the references of live objects indicating that they are alive. The rest of the objects are then subject to garbage collection.
Then the free memory is merged and the occupied memory is compacted so that the live objects are contiguous.
Explain how garbage collection deals with circular references.
Circular referencing issue happens when two objects refer to each other. Usually in a parent-child relationship, situations occur where a child interacts with the parent object and has a reference held to the parent object.
The .NET, the objects that are reachable from the root can be cleaned up easily. Thus, this can even be applied to circular reference and have the objects holding the resources cleaned up.
What is user-defined data type?
Answer
A user-defined type is a named data type created by the user. It can be a distinct type sharing a common representation with some built-in data type or it can be a structured type which has a sequence of named attributes that each has a type. Thus based on this it can be categorized as:
-Distinct type
-Structured type
-Reference type
Classes vs. Structures
Answer
The class is an extension of a structure.
Structure members have public access by default
Class member variables are private by default
The keyword for class is class
The keyword for structures is struct