Sunday, 30 August 2009

Assembly refresher

    1. The concept
      1. It’s a collection of one or more files containing type definitions and resource files like images, xml files etc used in your program.
      2. It also contains something called Manifest
        1. A manifest is a set of metadata tables that contains names of the files that are part of the assembly.
        2. It contains the metadata information about the assembly like its version, culture, publisher etc.
      1. It’s the smallest unit of deployment in .NET because CLR operates on Assembly.
      2. CLR always loads the file that contains the manifest metadata tables first and then uses it get the names of the files that are part of the assembly.
      3. You can have a multi-file assembly one of which can contain types that are frequently used, and the other ones containing types that are less likely to be used. This works well for programs that work over the internet. They only need to download the parts of the assembly that is mostly used. Other parts will be downloaded on demand.
        1. Its job of the CLR to load the parts of the assembly whenever required - locally or over the Internet, the address is present.
        2. You can use the multi-file assembly feature to
          1. add resource or data files to your assembly or
          2. you can also use it in case types are implemented using different programming languages, and combine them to produce a single assembly.
      1. The problem is that VS doesn't provide you the feature to create multi-file assembly, you will have to use command-line utilities like csc.exe
        1. All you do is create multiple .netmodules using csc.exe /t:module, and combine them using /addmodule switch.
        2. Lets have two C# files: Apple.cs and Mango.cs; do the following:
          1. csc /t:module Apple.cs [creates a .netmodule]
          2. csc /out:MyTypes.dll /t:library /addmodule:Apple.netmodule Mango.cs [creates an assembly]
        1. The resultant assembly will have two managed modules and one manifest
    2. Types of assemblies
      1. There are two types of assemblies in .NET:
        1. Weakly named, and
        2. Strongly named
      2. The fundamental difference between the two is that the strongly named assembly is signed with a publisher's public/private key pair that uniquely identifies the publisher.
      3. A strongly named assembly can be deployed either privately or publically. The GAC is the repository where CLR looks out for strong named public assemblies.
      4. Having a central repository means that the assemblies need more than just a filename to be distinguished. The following shows the Assembly folder before and after its exposed using the command: regsvr32 D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll -u

    AssemblyFolder AssemblyFolderExposed