Showing posts with label Assembly. Show all posts
Showing posts with label Assembly. Show all posts
Sunday, October 20, 2013
Monday, June 17, 2013
Assemblies and Side-by-Side Execution
Let
us consider that we have 2 applications A & B in a system, where A is an
old application using an older version (say x1) of an assembly, not B is a new
application and wants to use a new version (say x2) of the same assembly, how
can this be achieved?
If the Assemblies are private assemblies then we don’t have an issue as the applications A & B will contain their own version of the assembly in their application folder and use the assemblies independently. But what is the assembly is a shared assembly, how can be maintain and use 2 different versions of the same assembly? This is where side-by-side execution comes into play.
If the Assemblies are private assemblies then we don’t have an issue as the applications A & B will contain their own version of the assembly in their application folder and use the assemblies independently. But what is the assembly is a shared assembly, how can be maintain and use 2 different versions of the same assembly? This is where side-by-side execution comes into play.
What is a Global Assembly Cache (GAC)
The Global Assembly Cache (GAC) is a common folder where the shared assemblies are placed. The GAC folder is placed in one of the following folders.
X:/Windows/assembly (or) X:/Winnt/assembly Where X: is the driver where the .Net framework in installed, it might vary from machine to machine based on where the .Net Framework is installed. For an Assembly to be placed in the GAC, it should be signed with a strong name key, generated using the sn.exe utility. Once the assembly is signed with the key and is ready for deployment, it can be deployed in the GAC in one of the following ways.
Delay signing an Assembly
Delay signing is the process of delaying the actual signing process, if we use the normal signing process then the details of the private and public key will be available to all the developers who are involved in developing the Assembly.
The organization might want to restrict access to the private key only to a set of key individuals and not to all, delay signing process can be used to achieve this.
Delay signing can be achieved by specifying the AssemblyDelaySignAttribute attribute to true in the assemblyInfo file, on doing so the runtime will not sign the Assembly, but will reserve space in the PE file for the strong name which can be specified later.
Signing an Assembly
Signing an Assembly requires generating a key file and mapping it to a Shared assembly. There are 2 types of assemblies, private and shared assemblies. Private assemblies are private to the application and are placed in the same folder as the application files. Shared assemblies are those which are shared across multiple applications in the same machine.
Before we could sign an Assembly we need to generate a key file which will be used for signing. To sign the assembly we can use the .Net Utility sn.exe
sn.exe -k MyPublicPrivateKeyFile.snk
The key file contains a combination of private and public keys which will later be used by the publisher and the consumer to the assembly to establish a secured relationship.
Once the assembly key file is generated, it can be linked to the assembly in 2 ways.
Assembly Versioning
Assembly version details are stored in a file called AssemblyInfo, this file gets automatically created when you create a new project in Visual Studio, the version information of the assembly is specified in this file. A .Net Assembly version is a four part name, and contains the following Major Version Minor Version Build Version Release Version. The four parts of the Assembly version are organized as follows.
Dynamic Assemblies
As
the name suggests, Dynamic Assemblies
are those which are created dynamically at runtime. They are not stored in any
file before execution, after execution we can optionally store them in files. The System.Reflection.Emit namespace
contains classes that allow a compiler or tool to emit metadata and Microsoft
intermediate language (MSIL) and optionally generate a PE file on disk.
The Reflection.Emit namespace provides builder classes which can be used to create assemblies at runtime, these classes allow you to define classes and methods at runtime. The AssemblyBuilder is the core class which allows you to create assemblies at runtime.
AssemblyBuilder assemblyBuilder = curAppDomain.DefineDynamicAssembly(
assemblyName,AssemblyBuilderAccess.Save);
The Reflection.Emit namespace provides builder classes which can be used to create assemblies at runtime, these classes allow you to define classes and methods at runtime. The AssemblyBuilder is the core class which allows you to create assemblies at runtime.
AssemblyBuilder assemblyBuilder = curAppDomain.DefineDynamicAssembly(
assemblyName,AssemblyBuilderAccess.Save);
Static Assembly
Static Assemblies are the normal assemblies
which we create in .Net, they have physical class files and other related
resource files like, images, sound files etc. These physical files are compiled
into a single assembly file.
Static Assemblies can be private or public based on the type of target applications which use these assemblies. Private assemblies are used by individual applications, the assembly files are placed in the same folder/sub-folder of the application files. Shared assemblies are placed in the GAC and are shared across multiple applications in the system.
Static Assemblies can be private or public based on the type of target applications which use these assemblies. Private assemblies are used by individual applications, the assembly files are placed in the same folder/sub-folder of the application files. Shared assemblies are placed in the GAC and are shared across multiple applications in the system.
Satellite Assembly
Satellite Assemblies are used to create multilingual applications which needs to display information to the end users in multiple languages. Satellite assemblies do not contain any executable code, they contain only culture specific resource files which can be used by the main assembly to display details to the end user in their preferred language. Language specific resources should be created and compiled into Satellite Assemblies using the Assembly Linker tool Al.exe.
Shared Assembly
As
the name suggests a Public Assembly
or Shared Assembly is one which is
shared with various applications in the same system, hence these assembly files
cannot be placed in the individual application folders, and these assembly
files are placed in a common location in the machine called the Global Assembly Cache.
Public Assembly or Shared Assembly should have specific version information. All public / shared assemblies are placed in a common folder in the machine called the Global Assembly Cache. The GAC is usually located in the path C:\Windows\Assembly
Public Assembly or Shared Assembly should have specific version information. All public / shared assemblies are placed in a common folder in the machine called the Global Assembly Cache. The GAC is usually located in the path C:\Windows\Assembly
Public Assembly
As
the name suggests a Public Assembly
or Shared Assembly is one which is
shared with various applications in the same system, hence these assembly files
cannot be placed in the individual application folders, and these assembly
files are placed in a common location in the machine called the Global Assembly Cache.
Public Assembly or Shared Assembly should have specific version information. All public / shared assemblies are placed in a common folder in the machine called the Global Assembly Cache. The GAC is usually located in the path C:\Windows\Assembly
Public Assembly or Shared Assembly should have specific version information. All public / shared assemblies are placed in a common folder in the machine called the Global Assembly Cache. The GAC is usually located in the path C:\Windows\Assembly
Private Assembly
A Private
assembly is one which is used by an individual application; it is private
to that application and is not shared with any other application in the system.
Private assemblies are usually placed in the same folder or in a sub-folder
where the application files reside.
Private Assemblies do not have specific version information, since the parent application is just going to refer the latest assembly file in its folder/sub-folder.
Private Assemblies do not have specific version information, since the parent application is just going to refer the latest assembly file in its folder/sub-folder.
What are the types of Assemblies in .Net?
Assemblies can be categorized based
on various factors like, based on how they are shared between applications,
based on their physically state, based on how they are packed into files etc.
The following are the various types of assemblies based on the different classifications.
The following are the various types of assemblies based on the different classifications.
What does an Assembly contain?
An assembly
is the core building block of .Net, assemblies are self-contained, they contain
all the information required to process the assembly. Any .Net assembly
contains the following details.
1. The MSIL code of the assembly
2. Assembly Manifest
3. Type Metadata
4. Resources
Now let us see these in detail.
1. The MSIL code of the assembly
2. Assembly Manifest
3. Type Metadata
4. Resources
Now let us see these in detail.
What is an Assembly in .Net
An assembly is a collection of classes,
namespaces and related information which together form a complete application.
Every application which is developed in .Net is stored in an assembly.
Assembly can be either a self-executable file, with an extension of .EXE, or a library file with an extension of .DLL. Let us see more in details about both these types of assemblies.
Assembly can be either a self-executable file, with an extension of .EXE, or a library file with an extension of .DLL. Let us see more in details about both these types of assemblies.
Subscribe to:
Posts (Atom)

