Search notes:
.NET assembly
A
.NET assembly is the fundamental
reusable building block of a
common runtime language application: it exhibits a set of APIs, types and ressources that can be called or used by applications or other assemblies.
Assemblies are versionable and self-describing .
Self-describing means that all the information that the
Common Language Runtime (CLR) needs to run the assembly is stored with the assembly. Such an information is for example the list of the assemblies that the assembly depends on.
An assembly is created from one or more sources and compiled into a
DLL or an
EXE .
Unllike «ordinary» DLLs however, an assembly contains MSIL-instructions that can only be executed in the .NET runtime (as opposed to machine instructions that are executed directly on a CPU).
One or more assemblies can be packed into a library .
Assembly identity and strong name
An
assembly identity consists of an
assembly name (not fully qualified, obviously)
culture (RFC 1766 format)
version number
processor architecture (starting with .NET Framework 2.0)
If the assembly identity is augmented with the following information, it becomes a
strong name :
A strong name can be given to an assembly with
sn.exe
.
In
PowerShell , some of these characteristics can be determined like so:
PS C:\> [System.Reflection.Assembly ] $assembly = $true.psObject.GetType().Assembly
PS C:\> $assembly.FullName
System.Management.Automation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
PS C:\> [System.Reflection.AssemblyName] $name = [System.Reflection.AssemblyName]::GetAssemblyName($assembly.Location)
PS C:\> $name.CultureInfo
LCID Name DisplayName
---- ---- -----------
127 Invariant Language (Invariant Country)
PS C:\> $name.ProcessorArchitecture
MSIL
PS C:\> $name.Version
Major Minor Build Revision
----- ----- ----- --------
7 0 0 0
Assembly manifest
Every assembly contains an
assembly manifest which acts as a table of content for the assembly. The manifest stores:
The assembly's identity
A file table with the name of all files that make up an assembly (other .exe, .dlls or ressource files, bitmaps, readme files etc)
An assembly reference list
Locating assemblies of an application
The assemblies that are used by an application are typically found
The <codeBase>
element in the configuration file can be used to specify a different location.
Without a strong name , <codeBase>
can only refer to the application directory or one of its subdirectories.
Finding the location of an assembly (PowerShell)
PS C:\> [System.Data.SqlTypes.SqlDecimal].Assembly.Location
C:\Windows\Microsoft.Net\assembly \GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Show referenced assemblies
In
PowerShell , the assemblies that an assembly references can be shown like so:
PS C:\> $asmbl = [System.Reflection.Assembly ]::LoadFrom("P:\ath\to\the\assembly.dll")
PS C:\> $asmbl.GetReferencedAssemblies()
Version Name
------- ----
4.0.0.0 mscorlib
4.0.0.0 System.Data
1.0.0.0 YetAnotherAssembly
4.0.0.0 System
PS C:\> $asmbl.GetReferencedAssemblies().forEach( {$_.FullName} )
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
YetAnotherAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aab5e62e1b5f9c79
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Alternatively, referenced assemblies can also be shown with the IL disassembler
isldasm.exe
:
C:\> ildasm P:\ath\to\the\assembly.dll
After ildadsm has opened the assmbly, the referenced assemblies are shown when opening Manifest : they are labelled with .assembly extern …
.
Mixed-mode assemblies
Assemblies that were created with the C++/CLI compiler are referred to as
mixed-mode assemblies because they contain both native and
managed code .
Application Domains
Application domains provide isolation boundaries for assemblies. Such an isolation is used for purposes including
security
reliability
versioning
unloading assemblies
Filenames of assemblies in the GAC
The filename, without its
extension .dll
or
.exe
, of an assembly that is stored in the
GAC must correspond to the name of assembly itself.
Loading assemblies from the GAC
See also
Adding an assembly with the PowerShell cmdlet
add-type
System.AppDomain
implements an event that allows to respond to loading an assembly.
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Managed\User SID\Installer\Assemblies
HKCU\Software\Microsoft\Installer\Assemblies
PEVerify.exe
checks if an assembly contains
verifiably type-safe code .
FUSLOGVW.exe
is the
fusion log viewer (assembly binding log viewer) and can be used to diagnose the cause for an assembly not being able to be located by the
.NET Framework at runtime.