|
Assembly is smallest unit of deployment. An assembly consists of one or more files (dlls, exe's, html files etc) and represents a group of resources, type definitions and implementation of those types. An assembly may also contain references to other assemblies. The assembly manifest contains the version information. An assembly is the smallest unit that you use to define the version of an application. The version of an assembly determines the version of the types and the other resources that it contains.
The .Net framework allows the execution of multiple versions of the same assembly on the same machine. The side-by-side execution of assemblies overcomes the problem known as “DLL Hell”, which is one of the major problems associated with COM applications.
Assemblies are the smallest units to which the .Net framework grants permissions. They provide security boundaries within the .Net framework. When the assembly is loaded into the runtime, the assembly sends the request to the runtime to grant the permission. The permission granted depends on the policy files that are checked by the security engine of the runtime.
Assemblies are a fundamental part of programming with the .net framework. An assembly performs the following functions:
Functions or Features:
- It contains the code that a CLR executes.
- MSIL code in a portable executable file will not be executed if it doesn't contain the associated assembly manifest.
- Each assembly can have only one entry point( that is DllMain, WinMain, Main )
- It forms a security boundary. An assembly is a unit at which permissions are requested and granted.
- Type Boundary: Every type identity includes the name of the assembly in which its resides.
- Reference Scope Boundary: The assembly manifest contains assembly metadata that is used for resolving types and satisfying resources requests.
- Version Boundary: The assembly is the smallest versionable unit in the CLR, all types and resources in the same assembly are versioned as a unit.
- It forms a deployment unit: When an application starts, only the assemblies that the application initially calls must be present. Other assemblies, such as localization resources or assemblies containing utility classes can be retrieved on demand.
- Side-by-Side Execution is supported by assemblies.
Understanding Namespaces:
The .Net Framework class library consists of reusable classes, which are organized in hierarchical namespace. A namespace contains logically – and functionally- related classes and divides an assembly into a logical grouping of types. e.g. System.Data namespace contains all the classes that you require to build database applications, and System.IO namespace contains all the classes that you require to perform input and output operations within a program. Multiple assemblies can use the same namespace.
Assemblies can be staic or dynamic. The following is the defination for static and dynamic assemblies.
Static assemblies : Static assemblies can include .Net framework types (interface and classes) as well as resources for the assembly. Static assemblies are stored on disk in PE file.
Dynamic assemblies : The dynamic assemblies can be created using the .Net framework and they are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.
Assembly Contents
In general, a static assembly consists of four elements:
- Assembly Manifest
- Type metadata
- MSIL code that implements the type.
- Set of resources.
Note:-There are several ways to group these elements in assembly. Two ways to group these within a single file or with different set of files.
The elements of an assembly can be contained in several files. These files can be modules of compiled code (.netmodule), resources.
Assembly Manifest:
Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. Assembly Manifest contains the following information:
- Assembly Name: A text string specifying the assembly name.
- Version Number: A major, minor, revision and build number. The CLR uses these numbers to enforce version policy.
- Culture: Information on the culture or language the assembly supports. The information should be used only to designate an assembly as a satellite
- assembly containing culture- or language-specific information.
- Strong Name Information: The public key from the publisher if the assembly has been given a strong name.
- Type Reference Information: Information used by the runtime to map a type reference to the file that contains its declaration and implementation. This is used for types that are exported from the assembly.
Type Metadata:
The other component of assembly is type metadata. Metadata can be defined as data about the data; this means the metadata contains all the information about the assembly. Metadata defines the contents of the assembly. Metadata contains information such as:
- Classes that are there in the assembly.
- Interfaces, Events, Indexers that are used in the assembly.
- Structs and all the types' information.
MSIL Code
MSIL code is Microsoft intermediate language. The source code is compiled by .net compiler that will convert the source code into the IL code or MSIL code that is intermediate code and then this MSIL code that resides on PE file i.e. portable executable code convert into machine code using JIT with the help of CLR.
Types of Assembly:
There are three types of assembly.
- Private Assembly:- These are those assemblies, which are used by single application and are stored in the application directory or a sub-directory beneath. Here the scope of this assembly is limited to the application itself and this assembly can't be shared by multiple assemblies. If you want to use this private assembly, you have to either copy this assembly or paste under the bin folder or you can create the reference of this assembly using the Add reference dialog box and use this assembly. The limitation with the private assembly is that it can't be accessed by two application.
- Shared Assembly:- A shared assembly can be used by multiple assemblies. A shared assembly is normally stored in GAC (Global Assembly Cache), which is a repository of assemblies maintained by the .Net runtime. Shared assemblies are usually libraries of code which many applications will find useful e.g. crystal report classes which will be used by all application for reports.
- Satellite Assembly:- In multi lingual application in .Net to support multilingual functionality you can have modules which are customized for locations. These assemblies are called as satellite assemblies. Here in these assemblies we can distribute these assemblies separately than the core modules.
|