Show / Hide Table of Contents

Class AssemblyLocatorBase

Use a class derived from this class to get the fully qualified name of the file from which the assembly in which the derived class is defined was loaded. See Remarks.

Inheritance
System.Object
AssemblyLocatorBase
PropertyDefaults
Namespace: WizardWrx.Core
Assembly: WizardWrx.Core.dll
Syntax
public abstract class AssemblyLocatorBase : object
Remarks

Given the location from which an assembly was loaded, you can learn almost anything else you need to know about that file, such as its size, age, version, and directory. Given the directory, you can locate satellite files, such as configuration files that contain settings that it uses.

Constructors

| Improve this Doc View Source

AssemblyLocatorBase()

Initialize the one and only property of this class, which holds the fully qualified path from which the containing assembly was loaded.

Use this constructor to link the configuration file to the assembly that defines this class.

Declaration
public AssemblyLocatorBase()
Remarks

IMPORTANT: If the assembly loads from the Global Assembly Cache, its configuration file must be stored in the application directory. Be aware that if an assembly exists in the Global Assembly Cache, it loads from there, even if there is a copy in the application directory.

| Improve this Doc View Source

AssemblyLocatorBase(Assembly)

Initialize the one and only property of this class, which holds the fully qualified path from which the containing assembly was loaded.

Use this constructor to link the configuration file to the assembly that defines this class.

Declaration
public AssemblyLocatorBase(Assembly pasmLinkedAssembly)
Parameters
Type Name Description
Assembly pasmLinkedAssembly

Pass in a reference to the assembly to which the configuration file is linked. For example, you can use the executing assembly of the object at the top of the inheritance tree.

Remarks

IMPORTANT: If the assembly loads from the Global Assembly Cache, its configuration file must be stored in the application directory. Be aware that if an assembly exists in the Global Assembly Cache, it loads from there, even if there is a copy in the application directory.

Fields

| Improve this Doc View Source

_strAssemblyLocation

Once the energy required to gather the location has been expended, save it for future use.

Declaration
protected string _strAssemblyLocation
Field Value
Type Description
System.String
| Improve this Doc View Source

ASSEMBLYDATAPATH_TOKEN

Use this token in file names stored in DLL configuration files to explicitly state that the file is expected to inhabit the directory from which the assembly is loaded, unless the assembly was loaded from the Global Assembly Cache (GAC). In that case, substitute the application directory.

Declaration
public const string ASSEMBLYDATAPATH_TOKEN = null
Field Value
Type Description
System.String

Properties

| Improve this Doc View Source

AssemblyDataPath

Gets a string containing the fully qualified path of the directory from which the assembly was loaded, unless it was loaded from the Global Assembly Cache (GAC). In that case, the return value is the fully qualified name of the directory from which the first assembly was loaded into the current process. See Remarks.

Declaration
public string AssemblyDataPath { get; }
Property Value
Type Description
System.String
Remarks

So far as I know, assemblies must load from one of two locations. Unsigned assemblies MUST load from the application directory. If the assembly is signed with a strong name, it MAY be loaded from either the application directory or the Global Assembly Cache. If a signed assembly is in the local GAC, it loads from there, even if there is a copy in the application directory.

| Improve this Doc View Source

AssemblyLocation

Gets a string containing the fully qualified file name from which the assembly in which the derived class is defined was loaded.

Declaration
public string AssemblyLocation { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

DLLConfiguration

Gets a reference to the entire Configuration object tied to the assembly in which the derived class is defined.

Declaration
protected Configuration DLLConfiguration { get; }
Property Value
Type Description
Configuration
| Improve this Doc View Source

DLLSettings

Gets the DLL Settings section as a KeyValueConfigurationCollection.

Declaration
protected KeyValueConfigurationCollection DLLSettings { get; }
Property Value
Type Description
KeyValueConfigurationCollection
| Improve this Doc View Source

DLLSettingsSection

Gets a reference to the entire AppSettingsSection object tied to the assembly in which the derived class is defined.

Declaration
protected AppSettingsSection DLLSettingsSection { get; }
Property Value
Type Description
AppSettingsSection
Remarks

Since this property starts from the ConfigurationManager object returned by its DLLConfiguration sibling, it requires only a single statement, with a little help from an explicit cast.

| Improve this Doc View Source

MissingConfigSettings

This read-only property returns a generic List of string, each of which is a message that names a property that was omitted from the configuration file, along with its default value.

Declaration
public UnconfiguredDLLSettings MissingConfigSettings { get; protected set; }
Property Value
Type Description
UnconfiguredDLLSettings
| Improve this Doc View Source

RecoveredConfigurationExceptions

This read only property returns a generic List of Exceptions that arose during the initialization phase of an instance, and were silently recovered, so that they can be reported for investigation.

Declaration
public System.Collections.Generic.List<RecoveredException> RecoveredConfigurationExceptions { get; }
Property Value
Type Description
System.Collections.Generic.List<RecoveredException>
Remarks

This property supersedes ConfigMessage, which returned the list of exceptions as one long string, discarding their all-important stack traces.

Methods

| Improve this Doc View Source

GetAssemblyBuildDate(DateTimeKind)

Return the LastWriteTime of the file that contains the executing assembly. For all practical purposes, that is the date on which the assembly was built.

Declaration
protected DateTime GetAssemblyBuildDate(DateTimeKind pdtmKind)
Parameters
Type Name Description
DateTimeKind pdtmKind

This DateTimeKind enumeration member specifies whether to report the LastWriteTime or the LastWriteTimeUtc.

Returns
Type Description
DateTime

The return value is a fully initialized DateTime structure, which contains the requested LastWriteTime (Local or UTC) of the file that contains the code of the executing assembly.

| Improve this Doc View Source

GetAssemblyVersion()

Return the Version structure, to expedite parsing its parts.

Declaration
protected Version GetAssemblyVersion()
Returns
Type Description
Version

The return value is the version component of the fully qualified assembly name.

| Improve this Doc View Source

GetAssemblyVersionString()

Return the complete version of the executing assembly.

Declaration
protected string GetAssemblyVersionString()
Returns
Type Description
System.String

The return value is a string representation of all version number "octets" - Major, Minor, Build, and Revision.

| Improve this Doc View Source

GetDLLSetting(String)

Return the specified setting value, as a string.

Declaration
public string GetDLLSetting(string pstrSettingsKey)
Parameters
Type Name Description
System.String pstrSettingsKey

This string is the name (key) of the desired setting.

Returns
Type Description
System.String

The return value is a string representation of the value stored in the named key.

| Improve this Doc View Source

SetPropertiesFromDLLConfiguration(Type)

Set the like named properties from the linked configuration file.

Declaration
protected AssemblyLocatorBase.PropertySourceCounts SetPropertiesFromDLLConfiguration(Type pderivedType)
Parameters
Type Name Description
Type pderivedType

When the derived class constructor calls this method, it must pass in a reference to its own Type property.

Returns
Type Description
AssemblyLocatorBase.PropertySourceCounts

The return value is the count of properties that were set.

Remarks

This can almost certainly be simplified by enumerating the settings, but either way risks a NOT FOUND exception.

This method uses some fairly tricky Reflection gymnastics to map the key names in a configuration file to property names on an object.

See Also

PropertyDefaults
  • Improve this Doc
  • View Source
Back to top Generated by DocFX