Table of Contents

Class AssemblyReference

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Represents a reference to an external .NET assembly, hosted by a common language runtime (CLR).

public class AssemblyReference : AssemblyDescriptor, IResolutionScope, IOwnedCollectionElement<ModuleDefinition>, IImplementation, IFullNameProvider, INameProvider, IModuleProvider, IHasCustomAttribute, IMetadataMember, IImportable
Inheritance
AssemblyReference
Implements
Derived
Inherited Members
Extension Methods

Constructors

AssemblyReference(AssemblyDescriptor)

Creates a new assembly reference, and copies over all properties of another assembly descriptor.

public AssemblyReference(AssemblyDescriptor descriptor)

Parameters

descriptor AssemblyDescriptor

The assembly to base the reference on.

AssemblyReference(MetadataToken)

Initializes a new assembly reference.

protected AssemblyReference(MetadataToken token)

Parameters

token MetadataToken

The token of the assembly reference.

AssemblyReference(Utf8String?, Version)

Creates a new assembly reference.

public AssemblyReference(Utf8String? name, Version version)

Parameters

name Utf8String

The name of the assembly.

version Version

The version of the assembly.

AssemblyReference(Utf8String?, Version, bool, byte[]?)

Creates a new assembly reference.

public AssemblyReference(Utf8String? name, Version version, bool publicKey, byte[]? publicKeyOrToken)

Parameters

name Utf8String

The name of the assembly.

version Version

The version of the assembly.

publicKey bool

Indicates the key provided by publicKeyOrToken is the full, unhashed public key used to verify the authenticity of the assembly.

publicKeyOrToken byte[]

Indicates the public key or token (depending on publicKey), used to verify the authenticity of the assembly.

Properties

HashValue

Gets or sets the hash value of the assembly reference.

public byte[]? HashValue { get; set; }

Property Value

byte[]

IsCorLib

Gets a value indicating whether the assembly descriptor references a Common Object Runtime standard library.

public override bool IsCorLib { get; }

Property Value

bool

Module

Gets the module that defines the member definition or reference.

public ModuleDefinition? Module { get; }

Property Value

ModuleDefinition

Remarks

For member references, this does not obtain the module definition that the member is defined in. Rather, it obtains the module definition that references this reference.

PublicKeyOrToken

Gets or sets the (token of the) public key of the assembly to use for verification of a signature.

public byte[]? PublicKeyOrToken { get; set; }

Property Value

byte[]

Remarks

If this value is set to null, no public key will be assigned.

When HasPublicKey is set to true, this value contains the full unhashed public key that was used to sign the assembly. This property does not automatically update the HasPublicKey property.

This property corresponds to the Culture column in the assembly definition table.

Methods

GetHashValue()

Obtains the hash value of the assembly reference.

protected virtual byte[]? GetHashValue()

Returns

byte[]

The hash value.

Remarks

This method is called upon initializing the HashValue property.

GetPublicKeyOrToken()

Obtains the public key or token of the assembly reference.

protected virtual byte[]? GetPublicKeyOrToken()

Returns

byte[]

The public key or token.

Remarks

This method is called upon initializing the PublicKeyOrToken property.

GetPublicKeyToken()

When the application is signed with a strong name, obtains the public key token of the assembly

public override byte[]? GetPublicKeyToken()

Returns

byte[]

The token.

ImportWith(ReferenceImporter)

Imports the assembly descriptor using the provided reference importer.

public override AssemblyReference ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The importer object to use.

Returns

AssemblyReference

The imported assembly reference.

IsImportedInModule(ModuleDefinition)

Determines whether the descriptor of the member is fully imported in the provided module.

public override bool IsImportedInModule(ModuleDefinition module)

Parameters

module ModuleDefinition

The module that is supposed to import the member.

Returns

bool

true if the descriptor of the member is fully imported by the module, false otherwise.

Remarks

This method verifies all references in the descriptor of the member only. It does not verify any additional data or contents (such as a method body) associated to the member.

Resolve()

Resolves the reference to the assembly to an assembly definition.

public override AssemblyDefinition? Resolve()

Returns

AssemblyDefinition

The assembly definition, or null if the resolution failed.