0% found this document useful (0 votes)
13 views

Assemblies in

Uploaded by

jasonjacob
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Assemblies in

Uploaded by

jasonjacob
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Assemblies in .

NET
16 October 2024 10:38

•Assemblies are the deployment units of .NET applications


•.NET applications consist of one or more assemblies
•.NET executables with the usual extension EXE or DLL are known by the term
assembly

Difference between an assembly and a native DLL or EXE?

Although they both have the same file extension, .NET assemblies include
metadata that describes all the types that are defined in the assembly, with
information about its members — methods, properties, events, and fields

The metadata of .NET assemblies also provides information about the files that
belong to the assembly, version information, and the exact information about
assemblies that are used.

.NET assemblies are the answer to the DLL hell we’ve seen previously with native
DLLs.
–occurs when a new application loads a new version of a DLL file, overwriting
previous version
–Such action breaks earlier applications that relied on original DLL

•Assemblies maintain version information that can be accessed by CLR, different


versions of an assembly can co-exist side by side without overwriting any
resources like DLL files

•Assemblies are self - describing installation units, consists of one or more files.
•One assembly could be a single DLL or EXE or it can be made of different files

•Assemblies can be private or shared.


•Private assembly
–installed at the same time as the application itself.
–located in the same directory as the application or subdirectories thereof.
–shouldn’t have any versioning problems with the application.
–No other application will ever overwrite private assemblies.
•Shared assembly
–several applications can use the same assembly and have a dependency on it.
–reduce the need for disk and memory space.
–many rules must be fulfilled — a shared assembly must have a version number, a
unique name
–it’s installed in the global assembly cache (GAC)
–The GAC enables you to share different versions of the same assembly on a
system.

•Features of Assemblies
1.self – describing
–Include metadata that describes the assembly
2.Version dependencies
–Storing the version of any referenced assemblies in the manifest makes it
possible to easily find deployment faults
3.loaded side by side
–Different versions of the same assembly to be used inside a single process
(Windows 2000)
4.Application domain
–A number of applications can run independently inside a single process.
–Faults in one application cannot directly affect other applications inside the same
process
5.ClickOnce deployment
–Installation can be as easy as copying the files that belong to an assembly. This
feature named ClickOnce deployment. [zero impact (xcopy) installation]

•Assembly Structure:
–Assembly consists of assembly metadata describing the complete assembly, type
metadata describing the exported types and methods, MSIL code, and resources
–All these parts be inside of one file or spread across several files

C Sharp 2024 Page 1


•Single assembly spread across three files
•Component.dll has assembly metadata, type metadata, and MSIL code, but no
resources
•the assembly uses picture and module but that is not embedded inside
Component.dll but referenced within assembly metadata
•A module has no assembly metadata; thus, the module itself has no version
information, nor can it be installed separately.
•All three files in this example make up a single assembly; the assembly is the
installation unit.
•It would also be possible to put the manifest in a different file.

•Assembly Manifests:
–part of Metadata, important part of assembly
–describes the assembly with all the information that ’s needed to reference it and
lists all its dependencies
–The parts of the manifest are
1.Identity — Name, version, culture, and public key
2.A list of files — Files belonging to this assembly,
A single assembly must have at least one file but may contain a number of files.
3.A list of referenced assemblies — All assemblies used from the assembly are
documented inside the manifest (version no, public key - uniquely identify
assemblies)
4.A set of permission requests - permissions needed to run this assembly
5.Exported types - included if they are defined within a module and the module is
referenced from the assembly; otherwise, they are not part of the manifest

•Private and Shared Assemblies:


–private assembly is found either in the same directory as the application, or
within one of its subdirectories.
–No naming conflicts with other classes or versioning problems
–Shared assembly must be unique and therefore must also have a unique name
called a strong name
–Part of the strong name is a mandatory version number
•Satellite Assemblies
–only contains resources
–useful for localization.
–Because an assembly has a culture associated, the resource manager looks for
satellite assemblies containing the resources of a specific culture

C Sharp 2024 Page 2


Press Ctrl+M, ildasm.exe displays the metadata for each type within the
ConsoleApplication17.exe assembly

C Sharp 2024 Page 3


•open the manifest, can see the version number and the assembly attributes, as
well as the referenced assemblies and their versions
•These kinds of assembly attributes set routinely in Visual Studio projects in
AssemblyInfo.cs, created automatically for all projects that creates an assembly

C Sharp 2024 Page 4


With Visual Studio, you can configure these attributes with the project properties,
right click open, Application settings, and Assembly Information

Creating modules and assemblies:


–A module is a DLL without assembly attributes
–it’s not an assembly, but it can be added to assemblies at a later time
–Create a module with /target:module of csc
–view this module using ildasm
–has a manifest, but there is no .assembly entry inside the manifest
–not possible to configure versions or permissions with modules; that can be done
only at the assembly scope
–find references to assemblies in the manifest of the module
–With the /addmodule option of csc, possible to add modules to existing
assemblies

Creating single file assembly


•Open an notepad
•Create a namespace ClassLibrary1

C Sharp 2024 Page 5


•Create a namespace ClassLibrary1
•Create an abstract class car
•Save the file as ClassLibrary1.cs
•Create a .netmodule file by compiling the .cs file

csc /target:module ClassLibrary1.cs

C Sharp 2024 Page 6


•Include the following code also in ClassLibrary1.cs
•Two classes SportsCar and MiniVan inherited from Car class
•Override the abstract method TurboBoost()

•Compile the file ClassLibrary1.cs with /target:module


•Now open and view the assembly of ClassLibrary1.netmodule using ildasm

C Sharp 2024 Page 7


•Create an assembly, which includes the module ClassLibrary1.netmodule

csc /target:library /addmodule:ClassLibrary1.netmodule /out:ClassAssembly.dll

•Type ildasm and see the manifest of ClassAssembly.dll

C Sharp 2024 Page 8


C Sharp 2024 Page 9
C Sharp 2024 Page 10
C Sharp 2024 Page 11

You might also like