Вы находитесь на странице: 1из 25

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.
 Assemblies are a fundamental part of programming with
the .NET Framework.
 An assembly performs the following functions:
1. It contains code that the common language runtime
executes.
2. It forms a security boundary. An assembly is the unit at
which permissions are requested and granted.
 3. It forms a reference scope boundary. The assembly's manifest contains
assembly metadata that is used for resolving types and satisfying resource
requests. It specifies the types and resources that are exposed outside the
assembly. The manifest also enumerates other assemblies on which it
depends.
4. It forms a version boundary. The assembly is the smallest versionable
unit in the common language runtime; all types and resources in the same
assembly are versioned as a unit. The assembly's manifest describes the
version dependencies you specify for any dependent assemblies.
5. 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. This allows applications to be kept
simple and thin when first downloaded.
6. It is the unit at which side-by-side execution is supported.
Assemblies can be static or dynamic. Static assemblies can include .NET
Framework types (interfaces and classes), as well as resources for the
assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies
are stored on disk. You can also use the .NET Framework to create
dynamic assemblies, which are run directly from memory and are not
saved to disk before execution. You can save dynamic assemblies to disk
after they have executed.
IN C language

First.c metadata

Code
Tcc first.c
[machine dependent
format]
first.exe
X86 Inst’ns set
Executable
files
IN C language
 Metadata it is going to act like a repository which
maintains the information of the header file
 Code  this code will be in the form of machine
dependent only then the OS of the system,which will
be in a position to understand.
 X86 instructions it is going to provide on which
platform it can work,where exactly the application
can execute.
IL/Assembly

First.vb metadata

Code
Vbc first.vb
[machine independent
format] [MSIL]
first.exe
Resources
IL/Assembly
Manifest
IL/Assembly
 Meta data  in ‘C’ it is header file and in .net it is called as base
class libraries
It acts like a repository which maintains the information about
the assemblies ie Base Class libraries used with in the assembly.
 Code  it is a machine independent code in the format of MSIL
instructions.OS can’t understand the code.
 Resources  is goind to be collection which maintains the
information of external resources like
audio,vedio,icons,cursors,culture specific information etc used
within the assembly.
 Manifest  provides the information about the current assembly.
 If the assembly is of type exe then that is binded to “Portable
Executable Wrapper” the function is to invoke a CLR such that
you get the native code of the OS
metadata P
E
Code
[machine independent W
CLR
format] [MSIL] R
A
Resources P Native
P code
Manifest E of the OS
R
ASSEMBLY
 The compiled source of the .net application
is called as an Assembly
Dot net source

Assembly

.exe .dll
The 3 Types
 ~~~ Private Assembly (Default)
 ~~~ Shared Assembly
 ~~~ Satellite Resource Assembly
Private Assembly
 Ifthe assembly is of type private then
that assembly will always be binded to
the application itself. {OR} A private
assembly is normally used by a single
application, and is stored in the
application's directory, or a sub-
directory beneath.
 Note if the assembly is referred by ‘N’
no of applications then ‘N’ no of
assembly copies will be created at the
relevant folder of the application
Source.VB

vbc /t:library source.vb

Appl’n1.exe
Source.dll C:\app’n 1 Bin
source.exe
Appl’n2.exe
C:\app’n 2 Bin
Business Object / source.exe
.net component Appl’n3.exe
C:\app’n 3 Bin
source.exe

PRIVATE ASSEMBLY
Steps to define an
assembly using VS.Net IDE
 1. Select class library template.
 2. Specify the name of the class library.
– Note:The name of the class library will be
implicitly considered as the namespace name
for the library.
 3. Write the code as per the requirement.
SHARED ASSEMBLY
 The assemblies will be shared among all
the applications.{OR} shared assembly is
normally stored in the 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. the .NET framework
classes.

 Note the state of the assembly will be


maintained for all the applications.
Sn –K <Strongname.snk>

Strong name
SHARED ASSEMBLY
Source.VB

vbc /t:library source.vb


C:\winnt\assembly

Global
Source.dll Assembly C:\app’n 1 Bin App1.exe
Cache

C:\app’n 2 Bin App2.exe

C:\app’n 3 Bin App3.exe


Gacutil –i<assembly>
Global Assembly Cache
 Each computer where the common
language runtime is installed has a
machine-wide code cache called the global
assembly cache. The global assembly cache
stores assemblies specifically designated to
be shared by several applications on the
computer. You should share assemblies by
installing them into the global assembly
cache only when you need to.
 gac : it is in C:\WINNT\assembly
Strong Name
 Strong name—An assembly name that is globally
unique among all .NET assemblies. A public key
encryption scheme is used to create a digital
signature to insure that the strong name is truly
different than all other names created at anytime and
anywhere in the known universe. The digital
signature also makes it easy to encrypt the assembly,
authenticate who created the assembly, and to
validate that the assembly hasn't been corrupted or
tampered with.
POINTS TO REMEMBER
 In order to define an assembly as a shared it has to be
registered on to the GAC [ Global Assembly Cache ]
 GAC is a special folder which is capable to maintain
the information about the assemblies.
 GAC will never identify an assembly with its name.
 GAC has a capability to maintain the assemblies with
the same name
 In order to register an assembly on to a GAC it is
mandatory that the assembly should be binded with a
strong name.
 Binding a strong name to an assembly doesn’t mean
that the assembly is a shared it is still considered as a
private assembly only.
 If an assembly is binded with a strong name is called
as “strong assembly” else it is called “weak assembly”
Steps to define a shared assembly
 Step 1} a)Define a strong name.
Syntax  [ in dot net command prompt ]
sn –k <strongname.snk>
note: the extension for the strong name file can be either
.snk(strong name key file) or .txt
 Step 2} b)Bind the strong name to the assembly source.
To do: Import the system.reflection namespace
where reflectionamespace is an API which provides the
information about the assembly to set or to retrieve the value
from it.
C)Bind the strong name to the source of the assembly
<assembly:assemblykeyfile(“strongnamefile”)>
note: if the strong name file doesn’t exist in the same folder of the
assembly then the complete path of the strong name should be
specified.
D) write the code as per the requirement
E) Build the solution to define the class library.
Steps to define a shared assembly
 Step 3} F) Register the assembly on to the GAC
syntax :
gacutil –I<assembly>

 1.class library { choose this template }


 For ex a simple application to define a shared assembly and
to use it
 Step 1 :- c:\sn –k demo.snk
 Step 2 :- select class library template
for ex :- name – shared asseembly
step 3 :- imports system.reflection
<assembly:assemblykeyfile(“c:\demo.snk”)
 Imports system.data.oledb
Satellite Resource Assembly
 These are special assemblies which maintains the information
about the resource of the file.
 Usage  It is used to customize the dot net applications for a
specific cultures which is called as globalizations and
localizations of applications.
{OR}
 Satellite assemblies are often used to deploy language-specific
resources for an application. These language-specific
assemblies work in side-by-side execution because the
application has a separate product ID for each language and
installs satellite assemblies in a language-specific subdirectory
for each language. When uninstalling, the application removes
only the satellite assemblies associated with a given language
and .NET Framework version. No core .NET Framework files
are removed unless the last language for that .NET Framework
version is being removed.
 To achieve this the following namespace should be used 
system.globalization
To globalize the entire web application
 In Web.Config file there is a tag avialable called as
globalization we have to add attribute culture= and leave the
remaining as it is.
 <globalization culture=‘xx-XX’……../> where xx- is language
and XX is country/region.
 For e.g.: in web.config
 <globalization culture = “ar-SA” requestENcoding=“utf-8”
responseEncoding=“utf-8”/>
 This will display the results in arabic
Steps to achieve globalization of
application
 System.globalization

cultureInfo(culture)

system.threading
current culture
thread.currrentThread
currentUIculture

 CultureInfo : It is a class which provides the information about


the various cultures supported by the dot net tech.
Steps to achieve globalization of
application
 Current Culture  it is used to bind a specific culture to the
current processing thread such that the threads uses the binded
culture for its processing.
 CurrentUIculture  in order to project the information on the
user interface based on the binded culture,currentUIculture is
used.
 CultureInfo
DisplayName = Arabic(Saudi Arabia)
Name = ar-SA
Steps to achieve globalization of
application

 The following are the steps to achieve globalizations


 Import the following namespaces
system.globalizations
system.Threading
 Define a object for the culture info class
 Assign the cultureinfo object to the current culture and
currentUIculture property of the thread.currentThread.
For Forms
 The form which is going to set the culture is globalization
 The form which which is going to project the requested information is
called localization
 Note
 In order to localize an application satellite resource assembly are used.
 In order to support ‘n’ no of cultures ( n+1 ) satellite resource
assemblies should be defined.
 The name of the satellite resource assembly should be provided using
the following format
 mainresourceFileName.culture.resx
 For eg  form2.ar-SA.resx  for arabic culture of saudi arabia.

Вам также может понравиться