Saturday, 23 August 2014

c# Assemblies

Assembly
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, 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.

Contents of an Assembly
Ø  Type metadata.
Ø  The assembly manifest, which contains assembly metadata.
Ø  Microsoft intermediate language (MSIL) code that implements the types.
Ø  A set of resources


Types of Assemblies:
Assemblies are of four types
Ø  Private - The assembly is intended only for one application
Ø  Shared - If the assembly is to be made into a Shared Assembly(GAC)
Ø  Static – These are the .NET PE files that you create at compile time. 
Ø  Dynamic - These are PE-formatted, in-memory assemblies that you dynamically create at runtime


Strong Name:
A strong name is a .NET assembly name combined with its version number and other information to uniquely identify the assembly. This allows multiple versions of the same assembly to peacefully co-exist in the global assembly cache, where shared assemblies are typically stored. It consists of five parts as mentioned below
Ø  Simple Name – Usually the name of the file (without the extension) that contains the assembly
Ø  Public Key – RSA cryptographic public key that helps verify the assembly's authenticity
Ø  Version – Four-part version number, in the form of Major.Minor.Build.Revision
Ø  Culture – Target audience for the assembly, such as "neutral" (default audience), "en-us" (English – United States) or "fr" (France) etc.
Ø  Processor Architecture – Defines the assembly's format, such as MSIL (intermediate language) or x86 (binary for Intel x86 processors)




Steps to create Strong Name:

We have a set of steps that should be followed to create a strong name as shown below.
Ø  Open .net command prompt.
Ø  Go to the folder containing DLL.
Ø  Type sn -k test.snk, This will create  test .snk file in that folder.
Ø  Open the assemblyinfo.cs file of project.
Ø  Type file path  in this tag [assembly:AssemblyKeyFile@"C:\Yourpath\HP.snk")]
Ø  Build  application, finally your strong name created for your DLL.

Problems faced using Strong Name
Ø  Requires Exact Match. If you use strong names, your application or library must load the assembly with the exact strong name that you specify, including version and culture.
Ø  Cannot Lose Private Key. If your private key is lost or stolen, the security of your assembly is compromised. You will be forced to re-issue a new assembly signed with a new public-private key pair.


Delay Signing
It is signing an assembly with its strong name public key, which is freely distributable, instead of using the private key as usual. This allows developers to use and test a strong-named assembly without access to the private key. Then at a later stage (typically just before shipping the assembly), a manager or trusted key holder must sign the assembly with the corresponding private key. 


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

Ø  Culture is maintained in a text file which acts like a resource to the assembly.

No comments:

Post a Comment