Showing posts with label .Net Interview Questions. Show all posts
Showing posts with label .Net Interview Questions. Show all posts

Mar 8, 2009

.Net Interview Questions | Assembly - Part -3

11. Do you know BCL?
The BCL (Base Class Library) is a combination of classes or we can say that it’s a library of functionalities and types available to all languages that used in .NET Framework. To make the programmer job more easier dot net gave a advantage to includes the BCL in order to collect a large number of common functions, just like to read a file and write to file, graphic rendering, database interaction, and XML document manipulation at one place . The scope of this is large and standard libraries for most other languages, including C++, and would be comparable in scope to the standard libraries is just like Java. The BCL is sometimes incorrectly referred to as the Framework Class Library (FCL), which is a superset including the Microsoft namespaces.

12. In Assembly which work as GacBrowser ?
The GACPicker class allows the user to select an assembly from the Global Assembly Cache. It does this by looking at the filesystem representation of the GAC, since there appears to be no actual API in the current .NET environment.

.Net Interview Questions | [Assembly]

.Net Interview Questions | Assembly - Part -2

6. How strong name being defined? OR What is strong name?
A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature. It is generated from an assembly file (the file that contains the assembly manifest, which in turn contains the names and hashes of all the files that make up the assembly), using the corresponding private key. There are SDK tools to sign an assembly with strong name. Assemblies with the same strong name are expected to be identical.

7. How to Sign an Assembly with strong Name?
The Windows Software Development Kit (SDK) provides several ways to sign an assembly with a strong name:
• Using the Assembly Linker(Al.exe) provided by the Windows SDK.
• Using assembly attributes to insert the strong name information in your code. You can use either the AssemblyKeyFileAttribute or the AssemblyKeyNameAttribute, depending on where the key file to be used is ocated.
Note: In the .NET Framework version 2.0, some compilers issue warning messages when attributes are used.
To create and sign an assembly with a strong name using the Assembly Linker
At the command prompt, type the following command:
al /out: /keyfile:
In this command, assembly name is the name of the assembly to sign with a strong name, module name is the name of the code module used to create the assembly, and file name is the name of the container or file that contains the key pair.
The following example signs the assembly MyAssembly.dll with a strong name using the key file sgKey.snk.
al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk

To sign an assembly with a strong name using attributes
In a code module, add the AssemblyKeyFileAttribute or the AssemblyKeyNameAttribute, specifying the name of the file or container that contains the key pair to use when signing the assembly with a strong name.
The following code example uses the AssemblyKeyFileAttribute with a key file called sgKey.snk, located in the directory where the assembly is compiled. This assumes that the assembly is compiled using the command-line compilers vbc.exe and csc.exe.
Visual Basic


8. What is delay signing?
When signing an assembly, you might not always have access to a private key. For example, an organization might have a closely guarded key pair that developers do not have access to on a daily basis. While the public key might be available, access to the private key is restricted to a few individuals. In such a case, you can use delayed or partial signing to provide the public key, deferring the addition of the private key until the assembly is handed off.
Delay signing can be enabled in the Signing pane of the Project Designer as follows.
To delay sign an assembly
• With the project node selected in Solution Explorer, from the Project menu, click Properties (or right-click the project node in Solution Explorer, and click Properties).
• In the Project Designer, click the Signing tab.
• Select the Sign the assembly check box.
• Specify a key file. (ie key.snk)
• Select the Delay sign only check box. Note that a delay signed project will not run and cannot be debugged. You can, however, use the Strong Name Tool (Sn.exe) with the -Vr option to skip verification during development.

9. What is version number and Culture into Manifest?
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.For example ... - 1.02.0012.0113
Culture:- This relates to Satellite assembly. This information should be used only to Pick an assembly as a satellite assembly containing culture- or language-specific information.

10. What do you mean by satellite assemblies?
The assemblies which contains only culture information are known as satellite assemblies.This assembly is used to get language specific resources for an application.
To know how to create satellite assmblies refer to

.Net Interview Questions | [Assembly]

.Net Interview Questions | Assembly - Part -1

1. What you mean by Assembly?
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest.

2. What is menifest?

Detailed description of the assembly contents. A manifest contains metadata describing the name, resources, types, and version of the assembly as well as dependencies upon other assemblies. The manifest makes an assembly self-describing, easier to deploy, and not bound to a particular system because of storing data in the Windows registry.

3. How many type of assembly are there?
There are two types of Assembly in .NET
• Private Assembly
• Shared Assembly
Private Assembly: These are simple assemblies and being copied with each applications running folder.Dont nned to have strong name.
Shared Assembly: Also named as Strong Named Assemblies are copied to a single location (usually the Global assembly cache). For all calling assemblies within the same application, the same copy of the shared assembly is used from its original location. Hence, shared assemblies are not copied in the private folders of each calling assembly. Each shared assembly has a four part name including its face name, version, public key token and culture information. The public key token and version information makes it almost impossible for two different assemblies with the same name or for two similar assemblies with different version to mix with each other.
An assembly can be a single file or it may consist of the multiple files. In case of multi-file, there is one master module containing the manifest while other assemblies exist as non-manifest modules. A module in .NET is a sub part of a multi-file .NET assembly. Assembly is one of the most interesting and extremely useful areas of .NET architecture along with reflections and attributes.

4. What is GAC? WhereGAC located on machine?
GAC is known as Global Assembly Cache where the shared assembiles are being kept. GAC can be found on a system at \\Assembly ie. C:\Windows\Assembly

5. Can we have two DLL with same name into GAC?
GAC is a Folder that contains DLL that have strong name.We can say that GAC is a very special folder, and it is not possible to place two files with the same name into a Windows folder,But GAC differentiates DLL by strong names and since strong name can not be same hence wwe can put two DLL with same name into GAC. For example SameNameApp.dll and SameNameApp.dll to co-exist in GAC if the first one have version and the second have

.Net Interview Questions | [Assembly]

.Net Interview Questions | Assembly

In this section I included only questions related to Assembly.

1. What is assembly?
2. What is manifest?
3. How many type of assembly are there?
4. What is GAC? Where you found GAC on a machine?
5. Can we have two DLL with same name into GAC?
6. What is strong name?
7. How to Sign an Assembly with strong Name?
8. What is delay signing?
9. What is version number and Culture into Manifest?
10. What do you mean by satellite assemblies?
11. Do you know BCL?
12. In Assembly which work as GacBrowser ?

Answers [1-5] [6-10] [11-12]

Jun 27, 2008

Abstract Classs vs Virtual Methods

Abstract Class:
Abstract class is a class that has no direct instances, but whose descendants may have direct instances. There are case in which it is useful to define classes for which the programmer never intends to instantiate any objects; because such classes normally are used as bae-classes in inheritance hierarchies, we call such classes abstract classes These classes cannot be used to instantiate objects; because abstract classes are incomplete. Derived classes called concrete classesmust define the missing pieces.

Abstract classes normally contain one or more abstract methods or abstract properties, such methods or properties do not provide implementations, but our derived classes must override inherited abstract methods or properties to enable obejcts ot those derived classes to be instantiated, not to override those methods or properties in derived classes is syntax error, unless the derived class also is an abstract class.

In some cases, abstract classes constitute the top few levels of the hierarchy, for Example abstract class Shape with abstract method Draw() has tow derived abstract classe Shape2D & Shape3D inherites the method Draw() & also do not provide any implementation for it. Now we have normal classes Rectangle, Square & Circle inherites from Shape2D, and another group of classes Sphere, Cylinder & Cube inherites from Shape3D. All classes at the bottom of the hierarchy must override the abstract method Draw().

A class is made abstract by declaring it with Keyword abstract.

public abstract class Shape
//...Class implementation

public abstract void Draw(int x, int y)
//this method mustn't be implemented here.
//If we do implement it, the result is a Syntax Error.
public abstract class Shape2D : Shape
//...Class implementation
// do not have to implement the the method Draw(int x, int y)

public class Cricle : Shape2D
//here we should provide an implemetation for Draw(int x, int y)
public override void Draw(int x, int y)
//draw the shape

Difference between an abstract method & virtual method:
Virtual method
has an implementation & provide the derived class with the option of overriding it. Abstract method does not provide an implementation & forces the derived class to override the method.

Important Notes:

(a)Any Class with abstract method or property in it must be declared abstract
(b)Attempting to instantiate an object of an abstract class retults in a compilation error

Shape m_MyShape = new Shape(); //it is Wrong to that.

But we can do that.
Shape m_MyShape = new Circle(); // True

Shape m_MyShape;

declare refrences only, and the refrences can refer to intances of
any concrete classes derived from abstract class

Circle m_MyCircle = new Circle();
m_MyShape = m_MyCircle; // Also True
(d)An abstract class can have instance data and non-abstract methods -including constructors-.