Sunday, March 9, 2014

Assembly


Assembly

  • Def: An assembly is the container of compiled code of .NET applications.
  • It contains the code in MSIL (Microsoft Intermediate Language) language.
  • At run time, it will be compiled by CLR‘s JIT compiler into machine language.
  • The assembly file (with .exe or .dll extension) will be generated in the project folder \bin folder, after compilation.
TYPES OF ASSEMBLIES (BASED ON EXTENSION):
  1. Executable Assemblies / Process Assemblies / Private Assemblies (with .EXE extension)

    a. This is generated with

    • Console Applications
    • Smart Device Applications
    • Windows Applications
  2. b. These files are ready for execution. You can execute those by simply double clicking.

    Limitation: The code in this assembly is not accessible from other projects.

  3. Library Assemblies / Re-usable Assemblies / Shared Assemblies (with .DLL extension)

    i. This is generated with

    • Class Library
    • Windows Forms Control Library

    ii. These are non-executable files.

    Advantage: The code is this assembly is accessible from other projects.

Overview of “Class Library” Project
  • A class library project is meant for the development of Shared Assemblies.
  • The shared assemblies are re-usable in other applications also. 
  • That means the class library‘s code is re-usable in other applications, whenever required.
  • Class library project contains only user-defined classes.
  • Whenever the class library project is compiled, a library assembly file (with .DLLextension) will be generated in the ―bin\Debug folder.
  • The class library project can‘t be executed directly unlike console applications, windows applications etc.
Class Library
Global Assembly Cache (GAC):

All the shared assemblies should be saved in the GAC. GAC offers the following advantages.

  • Unique identification of the shared assemblies.
  • Avoids the DLL hell (replacement of an assembly related to one application, by another application).
  • Faster accessibility.

To view the currently installed assemblies in the GAC, open the following folder C:\windows\assembly The above folder is able to contain multiple dll files with same name, with different versions.

STRONG NAME KEYS (SNK):

The strong name key is a file, which acts as a unique identifier, for the shared assemblies, stored in the GAC. In other words, GAC recogniz es the assembly with this strong name only.