Wednesday, November 14, 2007

Dot Net Interview Questions - Part 2

  1. What are Satellite Assemblies? How you will create this? How will you get the different language strings?
    Satellite assemblies are often used to deploy 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. When uninstalling, the application removes only the satellite assemblies associated with a given language and .NET Framework version. No core .NET Framework files are removed unless the last language for that .NET Framework version is being removed.
    (For example, English and Japanese editions of the .NET Framework version 1.1 share the same core files. The Japanese .NET Framework version 1.1 adds satellite assemblies with localized resources in a \ja subdirectory. An application that supports the .NET Framework version 1.1, regardless of its language, always uses the same core runtime files.)
  2. How will u load dynamic assembly? How will create assemblies at run time?
  3. What is Assembly manifest? what all details the assembly manifest will contain?
    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.
    It contains Assembly name, Version number, Culture, Strong name information, List of all files in the assembly, Type reference information, Information on referenced assemblies.
  4. Difference between assembly manifest & metadata?
    assembly manifest -
    An integral part of every assembly that renders the assembly self-describing. The assembly manifest contains the assembly's metadata. The manifest establishes the assembly identity, specifies the files that make up the assembly implementation, specifies the types and resources that make up the assembly, itemizes the compile-time dependencies on other assemblies, and specifies the set of permissions required for the assembly to run properly. This information is used at run time to resolve references, enforce version binding policy, and validate the integrity of loaded assemblies. The self-describing nature of assemblies also helps makes zero-impact install and XCOPY deployment feasible.
    metadata - Information that describes every element managed by the common language runtime: an assembly, loadable file, type, method, and so on. This can include information required for debugging and garbage collection, as well as security attributes, marshaling data, extended class and member definitions, version binding, and other information required by the runtime.
  5. What is Global Assembly Cache (GAC) and what is the purpose of it? (How to make an assembly to public? Steps) How more than one version of an assembly can keep in same place?
    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.
    Steps
    - Create a strong name using sn.exe tool
    eg:
    sn -k keyPair.snk
    - with in AssemblyInfo.cs add the generated file name
    eg:
    [assembly: AssemblyKeyFile("abc.snk")]
    - recompile project, then install it to GAC by either
    drag & drop it to assembly folder (C:\WINDOWS\assembly OR C:\WINNT\assembly) (shfusion.dll tool)
    or
    gacutil -i abc.dll
  6. If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?
  7. How to find methods of a assembly file (not using ILDASM)
    Reflection
  8. What is Garbage Collection in .Net? Garbage collection process?
    The process of transitively tracing through all pointers to actively used objects in order to locate all objects that can be referenced, and then arranging to reuse any heap memory that was not found during this trace. The common language runtime garbage collector also compacts the memory that is in use to reduce the working space needed for the heap.
  9. What is Reflection in .NET? Namespace? How will you load an assembly which is not referenced by current assembly?
    All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly.
    Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for marshaling data across context/process/machine boundaries.
    Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).
  10. What is Custom attribute? How to create? If I'm having custom attribute in an assembly, how to say that name in the code?
    A: The primary steps to properly design custom attribute classes are as follows:
    1. Applying the AttributeUsageAttribute ([AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)])
    2. Declaring the attribute. (class public class MyAttribute : System.Attribute { // . . . })
    3. Declaring constructors (public MyAttribute(bool myvalue) { this.myvalue = myvalue; })
    4. Declaring properties
      public bool MyProperty
      {
      get {return this.myvalue;}
      set {this.myvalue = value;}
      }

The following example demonstrates the basic way of using reflection to get access to custom attributes.
class MainClass
{
public static void
Main()
{
System.Reflection.MemberInfo info = typeof(MyClass);
object[] attributes = info.GetCustomAttributes();
for (int i = 0; i <>
{
System.Console.WriteLine(attributes[i]);
}
}
}

  1. What is the managed and unmanaged code in .net?
    The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier. Compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed execution environment. Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services.
  2. How do you create threading in .NET? What is the namespace for that?
    System.Threading.Thread
  3. Serialize and MarshalByRef?
  4. using directive vs using statement :
    You create an instance in a using statement to ensure that Dispose is called on the object when the using statement is exited. A using statement can be exited either when the end of the using statement is reached or if, for example, an exception is thrown and control leaves the statement block before the end of the statement.
    The using directive has two uses:
    • Create an alias for a namespace (a using alias).
    • Permit the use of types in a namespace, such that, you do not have to qualify the use of a type in that namespace (a using directive).
  1. Describe the Managed Execution Process?
    The managed execution process includes the following steps:
    1. Choosing a compiler.
      To obtain the benefits provided by the common language runtime, you must use one or more language compilers that target the runtime.
    2. Compiling your code to Microsoft intermediate language (MSIL).
      Compiling translates your source code into MSIL and generates the required metadata.
    3. Compiling MSIL to native code.
      At execution time, a just-in-time (JIT) compiler translates the MSIL into native code. During this compilation, code must pass a verification process that examines the MSIL and metadata to find out whether the code can be determined to be type safe.
    4. Executing your code.
      The common language runtime provides the infrastructure that enables execution to take place as well as a variety of services that can be used during execution.
  1. What is Active Directory? What is the namespace used to access the Microsoft Active Directories? What are ADSI Directories?
    Active Directory Service Interfaces (ADSI) is a programmatic interface for Microsoft Windows Active Directory. It enables your applications to interact with diverse directories on a network, using a single interface. Visual Studio .NET and the .NET Framework make it easy to add ADSI functionality with the DirectoryEntry and DirectorySearcher components.
    Using ADSI, you can create applications that perform common administrative tasks, such as backing up databases, accessing printers, and administering user accounts. ADSI makes it possible for you to:
    • Log on once to work with diverse directories. The DirectoryEntry component class provides username and password properties that can be entered at runtime and communicated to the Active Directory object you are binding to.
    • Use a single application programming interface (API) to perform tasks on multiple directory systems by offering the user a variety of protocols to use. The DirectoryServices namespace provides the classes to perform most administrative functions.
    • Perform "rich querying" on directory systems. ADSI technology allows for searching for an object by specifying two query dialects: SQL and LDAP.
    • Access and use a single, hierarchical structure for administering and maintaining diverse and complicated network configurations by accessing an Active Directory tree.
    • Integrate directory information with databases such as SQL Server. The DirectoryEntry path may be used as an ADO.NET connection string provided that it is using the LDAP provider.

using System.DirectoryServices;

  1. How Garbage Collector (GC) Works?
    The methods in this class influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the age category, or generation, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. Alternatively, an application can force garbage collection using the Collect method.
    Garbage collection consists of the following steps:
    1. The garbage collector searches for managed objects that are referenced in managed code.
    2. The garbage collector attempts to finalize objects that are not referenced.
    3. The garbage collector frees objects that are not referenced and reclaims their memory.
  1. Why do we need to call CG.SupressFinalize?
    Requests that the system not call the finalizer method for the specified object.
    [C#]
    public static void SuppressFinalize(object obj);

The method removes obj from the set of objects that require finalization. The obj parameter is required to be the caller of this method.
Objects that implement the IDisposable interface can call this method from the IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize on an object that does not require it.

  1. What is nmake tool?
    The Nmake tool (Nmake.exe) is a 32-bit tool that you use to build projects based on commands contained in a .mak file.
    usage : nmake -a all
20 . What are Namespaces?
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. Even if you do not explicitly declare one, a default namespace is created. This unnamed namespace, sometimes called 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.

No comments: