Class AssemblyResolver
This is a static Assembly resolver and Assembly loader It takes care of caching and prevents that an Assembly is loaded twice (which would cause issues!)
Inheritance
Namespace:Dapplo.Addons.Bootstrapper.Resolving
Assembly:Dapplo.Addons.Bootstrapper.dll
Syntax
public static class AssemblyResolver : object
Properties
| Improve this Doc View SourceAssemblyCache
IEnumerable with all cached assemblies
Declaration
public static IEnumerable<Assembly> AssemblyCache { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Assembly> |
CheckEmbeddedResourceNameAgainstCache
Defines if before loading an assembly from a resource, the Assembly names from the cache are checked against the resource name. This speeds up the loading, BUT might have a problem that an assembly "x.y.z.dll" is skipped as "y.z.dll" was already loaded.
Declaration
public static bool CheckEmbeddedResourceNameAgainstCache { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Directories
Directories which this AssemblyResolver uses to find assemblies
Declaration
public static IEnumerable<string> Directories { get; }
Property Value
Type | Description |
---|---|
IEnumerable<System.String> |
Extensions
The extensions used for finding assemblies, you can add your own. Extensions can end on .gz when such a file/resource is used it will automatically be decompresed
Declaration
public static ISet<string> Extensions { get; }
Property Value
Type | Description |
---|---|
ISet<System.String> |
ResolveEmbeddedBeforeFiles
Defines if the resolving is first loading internal files, if nothing was found check the file system There might be security reasons for not doing this.
Declaration
public static bool ResolveEmbeddedBeforeFiles { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceAddDirectory(String)
Add the specified directory, by converting it to an absolute directory
Declaration
public static void AddDirectory(string directory)
Parameters
Type | Name | Description |
---|---|---|
System.String | directory | Directory to add for resolving |
FindAssemblies(IEnumerable<String>, IEnumerable<String>)
Find the specified assemblies from a manifest resource or from the file system. It is possible to use wildcards but the first match will be loaded!
Declaration
public static IEnumerable<Assembly> FindAssemblies(IEnumerable<string> assemblyNames, IEnumerable<string> extensions = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | assemblyNames | IEnumerable with the assembly names, e.g. from AssemblyName.Name, do not specify an extension |
IEnumerable<System.String> | extensions | IEnumerable with extensions to look for, defaults will be set if null was passed |
Returns
Type | Description |
---|---|
IEnumerable<Assembly> | IEnumerable with Assembly |
FindAssembly(String, IEnumerable<String>)
Find the specified assembly from a manifest resource or from the file system. It is possible to use wildcards but the first match will be loaded!
Declaration
public static Assembly FindAssembly(string assemblyName, IEnumerable<string> extensions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | assemblyName | string with the assembly name, e.g. from AssemblyName.Name, do not specify an extension |
IEnumerable<System.String> | extensions | IEnumerable with extensions to look for, defaults will be set if null was passed |
Returns
Type | Description |
---|---|
Assembly | Assembly or null |
LoadAssemblyFromFile(String)
Simple method to load an assembly from a file path (or returned a cached version). If it was loaded new, it will be added to the cache
Declaration
public static Assembly LoadAssemblyFromFile(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filepath | string with the path to the file |
Returns
Type | Description |
---|---|
Assembly | Assembly |
LoadAssemblyFromFileSystem(IEnumerable<String>, String, IEnumerable<String>)
Load the specified assembly from the specified directories, or return null
Declaration
public static Assembly LoadAssemblyFromFileSystem(IEnumerable<string> directories, string assemblyName, IEnumerable<string> extensions = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | directories | IEnumerable with directories |
System.String | assemblyName | string with the name without path |
IEnumerable<System.String> | extensions | IEnumerable with extensions to look for, defaults will be set if null was passed |
Returns
Type | Description |
---|---|
Assembly | Assembly |
LoadAssemblyFromFileSystem(String, IEnumerable<String>)
Load the specified assembly from the ResolveDirectories, or return null
Declaration
public static Assembly LoadAssemblyFromFileSystem(string assemblyName, IEnumerable<string> extensions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | assemblyName | string with the name without path |
IEnumerable<System.String> | extensions | IEnumerable with extensions to look for, defaults will be set if null was passed |
Returns
Type | Description |
---|---|
Assembly | Assembly |
LoadAssemblyFromStream(Stream, CompressionTypes, Boolean)
Simple method to load an assembly from a stream
Declaration
public static Assembly LoadAssemblyFromStream(Stream assemblyStream, CompressionTypes compressionType = CompressionTypes.None, bool checkCache = false)
Parameters
Type | Name | Description |
---|---|---|
Stream | assemblyStream | Stream |
CompressionTypes | compressionType | specify the compression type for the stream |
System.Boolean | checkCache | specify if the cache needs to be checked, this costs performance |
Returns
Type | Description |
---|---|
Assembly | Assembly or null when the stream is null |
LoadEmbeddedAssembly(Assembly, String)
Load the specified assembly from an embedded (manifest) resource, or return null
Declaration
public static Assembly LoadEmbeddedAssembly(this Assembly assembly, string resourceName)
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | Assembly to load the resource from |
System.String | resourceName | Name of the embedded resource for the assembly to load |
Returns
Type | Description |
---|---|
Assembly | Assembly |
LoadEmbeddedAssembly(String, IEnumerable<String>)
Load the specified assembly from a manifest resource, or return null
Declaration
public static Assembly LoadEmbeddedAssembly(string assemblyName, IEnumerable<string> extensions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | assemblyName | string |
IEnumerable<System.String> | extensions | IEnumerable with extensions to look for, defaults will be set if null was passed |
Returns
Type | Description |
---|---|
Assembly | Assembly |
Register(Assembly, String)
Extension to register an assembly to the AssemblyResolver, this is used for resolving embedded assemblies
Declaration
public static void Register(this Assembly assembly, string filepath = null)
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | Assembly |
System.String | filepath | Path to assembly, or null if it isn't loaded from the file system |
RegisterAssemblyResolve()
Register AssemblyResolve on the current AppDomain
Declaration
public static IDisposable RegisterAssemblyResolve()
Returns
Type | Description |
---|---|
IDisposable | IDisposable, when disposing this the event registration is removed |
RegisterAssemblyResolve(AppDomain)
Register the AssemblyResolve event for the specified AppDomain This can be called multiple times, it detect this.
Declaration
public static IDisposable RegisterAssemblyResolve(this AppDomain appDomain)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | appDomain |
Returns
Type | Description |
---|---|
IDisposable | IDisposable, when disposing this the event registration is removed |
UnregisterAssemblyResolve()
Unregister AssemblyResolve from the current AppDomain
Declaration
public static void UnregisterAssemblyResolve()
UnregisterAssemblyResolve(AppDomain)
Unregister the AssemblyResolve event for the specified AppDomain This can be called multiple times, it detect this.
Declaration
public static void UnregisterAssemblyResolve(this AppDomain appDomain)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | appDomain |