Assemblies in .NET
Assemblies in .NET
Introduction:
- In the Microsoft .NET
framework, an assembly is a partially compiled code library for use in
deployment, versioning and security. There are two types: process assemblies
(EXE) and library assemblies (DLL). A process assembly represents a process
which will use classes defined in library assemblies. .NET assemblies contain
code in CIL, which is usually generated from a CIL language, and then compiled
into machine language at run time by the CLR just-in-time compiler.
- An assembly can
consist of one or more files. Code files are called modules. An assembly can
contain more than one code module and since it is possible to use different
languages to create code modules it is technically possible to use several
different languages to create an assembly. Visual Studio however does not
support using different languages in one assembly.
- When you compile an
application, the MSIL code created is stored in an assembly . Assemblies
include both executable application files that you can run directly from
Windows without the need for any other programs (these have a .exe file
extension), and libraries (which have a .dll extension) for use by other
applications. Assemblies can be Process Assemblies i.e exe files or Library
Assemblies i.e dll files. Process assemblies are the processes which use library
assemblies in their execution.
- Even though assembly word can be used for EXE's as well but it
mainly refers to Dll's. Assemblies are also called Portable Executable s (PE) as
they can be easily carried and executed on any other system having CLR installed.
Parts Of An Assembly:
- Assembly Manifest :
It contains information about the assembly itself i.e name of assembly, version
number, security permissions, details of other assemblies it refers and strong
name for assembly if any. This manifest information is used by the CLR. The
manifest also contains the security demands to verify this assembly. It also
contains the names and hashes of all the files that make up the assembly. The
.NET assembly manifest contains a cryptographic hash of different modules in
the assembly. And when the assembly is loaded, the CLR recalculates the hash of
the modules at hand, and compares it with the embedded hash. If the hash
generated at run time is different from that found in the manifest, .NET refuses
to load the assembly and throws an exception this ensures security of an assembly.
- Type Meta Data :
Metadata means Data about the data. Metadata yields the types available
in that assembly, viz. classes, interfaces, enums, structs, etc., and their
containing namespaces, the name of each type, its visibility/scope, its base
class, the interfaces it implemented, its methods and their scope, and each
method’s parameters, type’s properties, and so on. The assembly metadata is
generated by the high-level compilers automatically from the source files. The
compiler embeds the metadata in the target output file, a dll, an .exe or a
.netmodule in the case of multi-module assembly( multi-module assembly is which contain multiple code files instead of just single file as in case of single assembly).
- Intermediate Language
(IL) : It is the actual code that is
implemented in an assembly i.e the high level code written using any .net language is compiled into Intermediate language which is then executed by Just-In-Time compiler in CLR.
- Resources : It is the
resources used by the assembly like resource files (.resx) for multilingual
sites or images or bitmaps used if any. Assembly will refer these resources at run time.
Types Of Assemblies:
- Private Assembly:
An assembly is used only for a particular application. It is stored in the
application's directory otherwise in the application's sub directory. There is
no version constraint in private assembly.
- Public/Shared
Assemblies : Refers to the assembly that is allowed to be shared by multiple
applications. A shared assembly must reside in Global Assembly Cache (GAC) with
a strong name assigned to it. For example, imagine that you have created a DLL
containing information about your business logic. This DLL can be used by your
client application. In order to run the client application, the DLL must be
included in the same folder in which the client application has been installed.
This makes the assembly private to your application. Now suppose that the DLL
needs to be reused in different applications. Therefore, instead of copying the
DLL in every client application folder, it can be placed in the global assembly
cache using the GAC tool. These assemblies are called shared assemblies.
- Satellite Assemblies
: A Satellite Assembly contains only static objects like images and other
non-executable files required by the application. "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, and the correct assembly is loaded into memory only if the user
selects to view the application in that language.
No comments:
Post a Comment