Rediger

Del via


MetadataAssemblyResolver.Resolve(MetadataLoadContext, AssemblyName) Method

Definition

Returns an assembly from a given assembly name.

public:
 abstract System::Reflection::Assembly ^ Resolve(System::Reflection::MetadataLoadContext ^ context, System::Reflection::AssemblyName ^ assemblyName);
public abstract System.Reflection.Assembly? Resolve (System.Reflection.MetadataLoadContext context, System.Reflection.AssemblyName assemblyName);
abstract member Resolve : System.Reflection.MetadataLoadContext * System.Reflection.AssemblyName -> System.Reflection.Assembly
Public MustOverride Function Resolve (context As MetadataLoadContext, assemblyName As AssemblyName) As Assembly

Parameters

context
MetadataLoadContext

The metadata load context object that represents the closed universe of Type objects loaded for inspection-only purposes.

assemblyName
AssemblyName

The name of the assembly.

Returns

The assembly for the provided assemblyName.

Remarks

Binding an assembly name to an assembly occurs when LoadFromAssemblyName is called or when a type from one assembly has a dependency on another assembly. The handler that overrides Resolve should use MetadataLoadContext.LoadFromStream, MetadataLoadContext.LoadFromAssemblyPath or MetadataLoadContext.LoadFromByteArray to load the requested assembly and return it.

To indicate the failure to find an assembly, the handler should return null rather than throwing an exception. Returning null commits the failure so that future attempts to load that name will fail without re-invoking the handler.

If the handler throws an exception, the exception will be passed through to the application that invoked the operation that triggered the binding. The MetadataLoadContext will not catch it, and no binding will occur.

The handler will generally not be called more than once for the same name, unless two threads race to load the same assembly. Even in that case, one result will win and be atomically bound to the name.

The MetadataLoadContext intentionally performs no ref-def matching on the returned assembly as what constitutes a ref-def match is a policy. It is also the kind of arbitrary restriction that MetadataLoadContext strives to avoid.

The MetadataLoadContext cannot consume assemblies from other metadata load contexts or other type providers (such as the underlying runtime's own reflection system). If a handler returns such an assembly, the MetadataLoadContext throws a FileLoadException.

Applies to