Wednesday 13 April 2016

Chetu Interview Question

1.What is an assembly ?
it is unit of deployment.It is a file generated on successful compilation of .Net application. it can be either a DLL or an EXE.

2.what are the features of Assembly?
a) They are self descrining. They consists of metadata which tells what are the methods,propeties etc present in the assembly.
b)Assembly can be loaded side-by side thus achieveing side by side execution.
c)installation of an assembly is easier.
d)Assemblies solve the DLL HELL problem.

2.Whats the diff bt a DLL and and EXE 
     
DLL
EXE
Dynamic Link Library with .dll extension
Executable with .exe extension
Can have many entry points
Has only one entry point
Does not contain UI
Contains UI
It is an in-process file.that means it runsin someone else’s memory
It is out-process file.It  can run independently. Its standalone.


2.What the physical location of assembly ?
 c:\Windows\assembly

3.Different types of  Assembly ?
a)Private Assembly
An assembly used by a single application is called private assembly. Its present in the bin folder.
b) SharedAssembly
An assembly used by more than one application.Its present in GAC.
c)Satellite Assembly
These are resource files which are compiled to assemblies.

4.What is DLL Hell ?
DLL HELL is a problem which arises when a new version of application with a new set of DLL overrides the older version.The application which are using older version of DLL crashes because those have been replaced by new DLL which are not compatible with the old applicaitons.

5.How is DLL Hell solved in .Net?
It is solved with the help of Assemblies.Assemblies allow different versions of DLL to co-exist among themselves.This feature is called Versioning.

6.What is Process ?
Instance of computer program that is being executed.

6.What are Application domains?
The domain in which your application runs. They provide isolation for running applications.
They are hosted inside Process.Single process can have more than one application domain. Communication between them can be achieved with the help of proxy.

7.How are Application domains created in C#?

static void Main()
{
    // Create an Application Domain:
    System.AppDomain newDomain = System.AppDomain.CreateDomain("NewAppDomain");

    // Load and execute an assembly:
    newDomain.ExecuteAssembly(@"d:\HelloWorld.exe");

    // Unload the application domain:
    System.AppDomain.Unload(newDomain);
}

8.What is PE file ?
Portable Executable File is either a DLL or an EXE.It is generated when a program is compiled.It consists of 3 part-
PE Header
MSIL
Metadat

8.What are the contents of an Assembly ?
An assembly consists-
a)Manifest
b)IL Code
c)Resource Files
d)Metadata

9.What is manifest ?

Manifest of an assembly contains the following-
a)Identity--consists of Assembly Name,Version No,Culture and Public Key Token.
b)List of File present in Assembly.
c)A list of referenced assemblies.
d)A set of permission requests.

10.What is metadata ?
Contains all the type and member information present in the code.

11.What is Single File and MultiFile assembly ?
Single File Assembly-it consists of only one file.

Multifile Assembly-consists of more then one files like- module(.netmodule), resource file(x.jpg) etc.All of them can be linked to form one assembly.

12.Whats the diff bt assembly and module ?
Assembly contains the manifest info.
modules does not have manifest info.They only contain metadata.They cannot be created in VS.

13.Can you compile an assembly with more than one file ?
Yes 

14.What is ILDASM ?
Its a tool used to view contents of an assembly.


15. what is ngen.exe ?
Native Image Generator.It compiles the entire assembly during installation.
It creates native images that are nothing but files so that the next time compiles compiles it picks up these images instead of files from JIT.
This helps in faster compilation.It can be used only if ngen is used for all the assembly in the application. 

16.What is GAC ?
It a a cache for assemblies which are globally available. For assemblies to be loadede in GAC they must have a strong name.Strong name ensures that assemblies with same name exists in GAC.

17.How do install and uninstall assembly in GAC ?
install- gacutil -i <assembly name>
uninstall-gacutil -u <assembly name>

18.What is strong name ?
Its  a .Net assembly name that consists of foll-
Name,Version,Culture Info and Public Key token.
It is used to help different versions of same assembly co-exist in GAC.

18.what is strong name key file?How is it created?
The snk.exe utility generated a public/private key pair that is stored in file called snk file(<name>.snk).it can be created by going to command prompt and typing-
                             snk -k <name>.snk

19.What do you mean by signing  a assembly
it means ensuring your software does not fall into wrong hands. this is done by creating a .snk file for the assembly and then it is used to sign the assembly by giving it a strong name. 
.Net uses digital signature to safe guard the integrity of an assembly .it follows Public-key cryptography.

20.Explain how public key cryptography works.
In this method both the sender and receiver will have set of keys know as public keys(which is used to encrypt a assembly) and private key(used to decrypt an assembly).when you sign an assembly using snk utility these two keys are embedded into the assembly. the assembly gets signed by the pubic key ,public key is freely distributed. the user who wants to use it must have the private key which is used to decrypt this assembly.

21.What is satellite assembly ?
satellite assembly consists of resource files which for a specific language.it can be used for localization and globalization.
read more about them here ads

22.what is shfusion.dll?
Its a dll that allows you to see the contents of GAC very easily.go to run command and type assembly ,it opens up a windows which shows the contents of assembly. 

23. What is Namespace?
The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types.
Within a namespace, you can declare one or more of the following types:
·
another namespace
· class
· interface
· struct
· enum
· delegate

Whether or not you explicitly declare a namespace in a C# source file, the compiler adds a default namespace. This unnamed namespace, sometimes referred to as the global namespace, is present in every file. Any identifier in the global namespace is available for use in a named namespace.
Namespaces implicitly have public access and this is not modifiable.
It is possible to define a namespace in two or more declarations.e.g: namespace MyCompany.Proj1{ class MyClass { }} namespace MyCompany.Proj1{ class MyClass1 { }}

Namespaces have the following properties:
· They organize large code projects.
· They are delimited by using the . operator.
· The using directive obviates the requirement to specify the name of the namespace for every class.
· The global namespace is the "root" namespace: global::System will always refer to the .NET Framework namespace System.

24. Explain About using Directive?

The using directive has two uses:
· To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace
· To create an alias for a namespace or a type. This is called a using alias directive.
The scope of a using directive is limited to the file in which it appears. Create a using alias to make it easier to qualify an identifier to a namespace or type.
Namespaces come in two categories: user-defined and system-defined. User-defined namespaces are namespaces defined in your code.

25. What is an application domain?
A boundary that the common language runtime establishes around objects created within the same application scope. Application domains help isolate objects created in one application from those created in other applications so that run-time behavior is predictable. Multiple application domains can exist in a single process.


26. What is an assembly in Microsoft.Net? 
A collection of one or more files versioned and deployed as a unit. It contains code that the common language runtime executes. It forms a security boundary. An assembly is the unit at which permissions are requested and granted. It forms a type boundary. Every type's identity includes the name of the assembly in which it resides. It forms a reference scope boundary. It forms a version boundary. It forms a deployment unit.
Assemblies can be an efficient way to manage resources in larger projects. Assemblies can contain one or more modules. For example, larger projects may be planned in such a way that several individual developers work on separate modules, all coming together to create a single assembly.
Assemblies have the following properties:
· Assemblies are implemented as .exe or .dll files.
· You can share an assembly between applications by putting it in the Global Assembly Cache.
· Assemblies must be strong-named before they can be included in the Global Assembly Cache.
· Assemblies are only loaded into memory if they are required.
· You can programmatically obtain information about an assembly by using reflection
· If you want to load an assembly only to inspect it, use a method such as ReflectionOnlyLoadFrom.
· You can use two versions of the same assembly in a single application.
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 can be private or shared. In order to share an assembly with other applications, it must be placed in the Global Assembly Cache (GAC).
private assembly: An assembly that is available only to clients in the same directory structure as the assembly.
shared assembly : An assembly that can be referenced by more than one application. An assembly must be explicitly built to be shared by giving it a cryptographically strong name.

satellite assembly : A .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place the resources for difference languages in different assemblies, and the correct assembly is loaded into memory only if the user elects to view that application in that language.

27. What is Global Assembly Cache?
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.
There are several ways to deploy an assembly into the global assembly cache:
· Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache.
· Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the Windows Software Development Kit (SDK).
· Use Windows Explorer to drag assemblies into the cache.
· Assemblies deployed in the global assembly cache must have a strong name. When an assembly is added to the global assembly cache, integrity checks are performed on all files that make up the assembly. The cache performs these integrity checks to ensure that an assembly has not been tampered with, for example, when a file has changed but the manifest does not reflect the change.

28. 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 using the corresponding private key.
You can ensure that a name is globally unique by signing an assembly with a strong name. In particular, strong names satisfy the following requirements:
· Strong names guarantee name uniqueness by relying on unique key pairs.
· Strong names protect the version lineage of an assembly. A strong name can ensure that no one can produce a subsequent version of your assembly.
· Strong names provide a strong integrity check. Passing the .NET Framework security checks guarantees that the contents of the assembly have not been changed since it was built.
· When you reference a strong-named assembly, you expect to get certain benefits, such as versioning and naming protection. If the strong-named assembly then references an assembly with a simple name, which does not have these benefits, you lose the benefits you would derive from using a strong-named assembly and revert to DLL conflicts. Therefore, strong-named assemblies can only reference other strong-named assemblies.

29. What is Assembly Manifest?
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 are the functions An Assembly manifest do?
· Enumerates the files that make up the assembly.
· Governs how references to the assembly's types and resources map to the files that contain their declarations and implementations.
· Enumerates other assemblies on which the assembly depends.
· Provides a level of indirection between consumers of the assembly and the assembly's implementation details.
· Renders the assembly self-describing.

30. List out the contents of assembly manifest?

Assembly name
Version number
Culture
Strong name information
List of all files in the assembly
Type reference information
Information on referenced assemblies

31. List out the contents of Assembly?
In general, a static assembly can consist of four elements:
· The 
assembly manifest, which contains assembly metadata.
· Type metadata.
· Microsoft intermediate language (MSIL) code that implements the types.
· A set of resources.

32. Explain the grouping of elements in to an assembly?
· There are several ways to group these elements in an assembly. You can group all elements in a single physical file, which is shown in the following illustration.
· Single-file assembly·
· alternatively, the elements of an assembly can be contained in several files. These files can be modules of compiled code (.net module), resources (such as .bmp or .jpg files), or other files required by the application.

33. When multifile assemblies required?
· Create a multifile assembly when you want to combine modules written in different languages and to optimize downloading an application by putting seldom used types in a module that is downloaded only when needed.
· The files that make up a multifile assembly are not physically linked by the file system. Rather, they are linked through the assembly manifest and the common language runtime manages them as a unit.

34. What is MetaData?

Metadata is binary information describing your program that is stored either in a common language runtime portable executable (PE) file or in memory. When you compile your code into a PE file, metadata is inserted into one portion of the file, while your code is converted to Microsoft intermediate language (MSIL) and inserted into another portion of the file. Every type and member defined and referenced in a module or assembly is described within metadata. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on.
Metadata describes every type and member defined in your code in a language-neutral manner.

35. What kind of information stored in Metadata?
Metadata stores the following information:
· Description of the assembly.
· Identity (name, version, culture, public key).
· The types that are exported.
· Other assemblies that this assembly depends on.
· Security permissions needed to run.
· Description of types.
· Name, visibility, base class, and interfaces implemented.
· Members (methods, fields, properties, events, nested types).
· Attributes.
· Additional descriptive elements that modify types and members.

36. What is Delaysigning?
An organization can have a closely guarded key pair that developers do not have access to on a daily basis. The public key is often available, but access to the private key is restricted to only a few individuals. When developing assemblies with strong names, each assembly that references the strong-named target assembly contains the token of the public key used to give the target assembly a strong name. This requires that the public key be available during the development process.
You can use delayed or partial signing at build time to reserve space in the portable executable (PE) file for the strong name signature, but defer the actual signing until some later stage (typically just before shipping the assembly).

37. Explain the steps to delaysign an assembly?
The following steps outline the process to delay sign an assembly:
1. Obtain the public key portion of the key pair from the organization that will do the eventual signing. Typically this key is in the form of an .snk file, which can be created using the 
Strong Name tool (Sn.exe) provided by the .NET Framework SDK.
2. Annotate the source code for the assembly with two custom attributes from System.Reflection:
· AssemblyKeyFileAttribute, which passes the name of the file containing the public key as a parameter to its constructor.
· AssemblyDelaySignAttribute, which indicates that delay signing is being used by passing true as a parameter to its constructor.
· [assembly:AssemblyKeyFileAttribute("myKey.snk")]
[assembly:AssemblyDelaySignAttribute(true)]
3. The compiler inserts the public key into the assembly manifest and reserves space in the PE file for the full strong name signature. The real public key must be stored while the assembly is built so that other assemblies that reference this assembly can obtain the key to store in their own assembly reference.
4. Because the assembly does not have a valid strong name signature, the verification of that signature must be turned off. You can do this by using the –Vr option with the Strong Name tool. 5. Later, usually just before shipping, you submit the assembly to your organization's signing authority for the actual strong name signing using the –R option with the Strong Name tool.
The following example signs an assembly called myAssembly.dll with a strong name using the sgKey.snk key pair.
sn -R myAssembly.dll sgKey.snk

38. Explain about friend assembly?
An internal type or internal member in an assembly can be accessed from another assembly.
The friend assemblies feature allows you to access internal members; private types and private members will remain inaccessible.

39. What is a satellite Assembly?
An assembly containing localized resources for another assembly.


No comments:

Post a Comment