Showing posts with label Assembly. Show all posts
Showing posts with label Assembly. Show all posts

.NET Assembly Interview Question with Answer

Can you create a native Image of ASP.NET assembly ... does this work ... is it possible ?

Native Image generator creates a local image of an .NET Assembly and installs that image in the native cache on the local machine. But when you create a Native Image of an ASP.NET assembly the .NET Runtime ignores that assembly and reverts back to JIT.

This is because CLR cannot load native images in a shared application domain and all ASP.NET applications run in a shared application domain. Hence although the native image of the assembly will be created it will not be installed in the image cache.

You've written an assembly that you want to use in more than one application. Where and how you will deploy it?

Assemblies that are to be used by multiple applications (for example, shared assemblies) are deployed to the global assembly cache. In the prerelease and Beta builds, use the /i option to the GACUtil SDK tool to install an assembly into the cache:


gacutil /i myDll.dll

Windows Installer 2.0, which ships with Windows XP and Visual Studio .NET will be able to install assemblies into the global assembly cache.

What is a Satellite Assembly ?

This assembly is used to get language specific resources for an application.These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.

Is versioning applicable to private assemblies?

Yes It is, However, Since a private assembly can only be called by applications that reside in the same folder Version control in private assemblies is not necessary.

private assembly is only for one application and updating it won't unintentionally break other applications.

Assembly In Microsoft.Net

What is an assembly in .NET Framework?
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 as accessible by code outside that unit.
Assemblies are self-describing by means of their manifest, which is an integral part of every assembly. The manifest:

What is assembly manifest?
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.
For an assembly with one associated file, the manifest is incorporated into the PE file to form a single-file assembly. You can create a multi-file assembly with a standalone manifest file or with the manifest incorporated into one of the PE files in the assembly.
Explain the information stored in assembly manifest.
Assembly manifest contains the following information:

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.

You can add or change some information in the assembly manifest by using assembly attributes in your code. You can change version information and informational attributes, including Trademark, Copyright, Product, Company, and Informational Version. 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. For an assembly with one associated file, the manifest is incorporated into the PE file to form a single-file assembly. You can create a multi-file assembly with a standalone manifest file or with the manifest incorporated into one of the PE files in the assembly.

What are the functions performed by the assembly manifest?
Each assembly's manifest performs the following functions:

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

What is GAC (Global Assembly Cache)?
Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache that 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.

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.

.NET Assembly Questions & Answer

How is the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.

What is a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

What namespaces are necessary to create a localized application?

System.Globalization and System.Resources.

What is the smallest unit of execution in .NET?
an Assembly.

When should you call the garbage collector in .NET?

As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.

How do you convert a value-type to a reference-type?
Use Boxing.

What happens in memory when you Box and Unbox a value-type?
Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.

Assembly

Q1.What do you understand Satellite Assemblies ?
Answer: This assembly is used to get language specific resources for an application.These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.

Q2.What do you know about dot NET assemblies?
Answer: Assemblies are the smallest units of versioning and deployment in the dot NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and dot NET remoting applications.

Q3.What is difference private and shared assembly?
Answer: Privateassembly used inside an application only and does not have to be identified by a strong name.
Shared assembly can be used by multiple applications and has to have a strong name.

Q4.What is strong name ?
Answer: A strong name includes name of assembly, version number, culture identity, and a public key token.

Q5.What is assembly ?
Answer: Assemblies are the building blocks of dot NET Framework applications; they form fundamental unit of deployment and version control and reuse and 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. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.

Q6. How can you debug failed assembly binds ?
Answer: Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.

Q7. Where are shared assemblies stored ?
Answer: Global assembly cache.

Q8. How can you tell the application to look for assemblies at the locations other than its own install ?
Answer: Use the directive in the XML .config file for a given application.

should do the trick. Or you can add additional search paths in the Properties box of the deployed application.

Q9.Where is global assembly cache located on the system ?
Answer: Usually C:\winnt\assembly or C:\windows\assembly.

Q10. How do you specify a custom attribute for the entire assembly (rather than for a class) ?
Answer: Global attributes must appear after any top-level using clauses and before the first type or namespace declarations. An example of this is as follows:
using System;
[assembly : MyAttributeClass] class X {}