.Net Runtime Library for Delphi
Close
Retrieving Setup Information from an Application Domain

Each instance of an application domain consists of both properties and AppDomainSetup information. You can retrieve setup information from an application domain using the wrapper class TClrAppDomain orAppDomain interface. This class or interface provides several members that retrieve configuration information about an application domain. You can also query the AppDomainSetup object for the application domain to obtain setup information that was passed to the domain when it was created.

The following example creates a new application domain and then prints several member values to the console.

Delphi
program AppDomain; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, CNClrLib.Host, CNClrLib.Core; var Console: _Console; domain: TClrAppDomain; begin try Console := CoConsole.CreateInstance; // Create the application domain. domain := TClrAppDomain.CreateDomain('MyDomain', nil); // Write application domain information to the console. Console.WriteLine_14('Host domain: ' + TClrAppDomain.GetCurrentDomain.FriendlyName); Console.WriteLine_14('New domain: ' + domain.FriendlyName); Console.WriteLine_14('Application base is: ' + domain.BaseDirectory); Console.WriteLine_14('Relative search path is: ' + domain.DefaultInterface.RelativeSearchPath); Console.WriteLine_15('Shadow copy files is set to: {0}', domain.DefaultInterface.ShadowCopyFiles); //NB: The DefaultInterface is the AppDomain Inteface. The TClrAppDomain is //a wrapper of the _AppDomain Dispatch Interface // Unload the application domain. TClrAppDomain.Unload(domain); Console.ReadKey; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. //Output //Host domain: DefaultDomain //New domain: MyDomain //Application base is: C:\Temp\AppDomainDemo\EXE\Win32\Debug\ //Relative search path is: //Shadow copy files is set to: False







The following example sets, and then retrieves, setup information for an application domain. Note that AppDomain.SetupInformation.ApplicationBase gets the configuration information.

Delphi
program AppDomain; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, CNClrLib.Host, CNClrLib.Core; var Console: _Console; domain: TClrAppDomain; domaininfo: _AppDomainSetup; begin try Console := CoConsole.CreateInstance; // Create application domain setup information. domaininfo := CoAppDomainSetup.CreateInstance; domaininfo.ApplicationBase := 'C:\Temp\AppDomainDemo\EXE\Win32\Debug\'; domaininfo.ConfigurationFile := 'C:\Temp\AppDomainDemo\EXE\Win32\Debug\AppDomain.exe.Config'; // Create the application domain. domain := TClrAppDomain.CreateDomain('MyDomain', nil, domaininfo); // Write application domain information to the console. Console.WriteLine_14('Host domain: ' + TClrAppDomain.GetCurrentDomain.FriendlyName); Console.WriteLine_14('child domain: ' + domain.FriendlyName); Console.WriteLine(); Console.WriteLine_14('Application base is: ' + domain.DefaultInterface.SetupInformation.ApplicationBase); Console.WriteLine_14('Configuration file is: ' + domain.DefaultInterface.SetupInformation.ConfigurationFile); //NB: The DefaultInterface is the AppDomain Inteface. The TClrAppDomain is //a wrapper of the _AppDomain Dispatch Interface // Unload the application domain. TClrAppDomain.Unload(domain); Console.ReadKey; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. //Output //Host domain: DefaultDomain //child domain: MyDomain // //Application base is: C:\Temp\AppDomainDemo\EXE\Win32\Debug\ //Configuration file is: C:\Temp\AppDomainDemo\EXE\Win32\Debug\AppDomain.exe.Config