AppDomain.BaseDirectory Property

Definition

Gets the base directory that the assembly resolver uses to probe for assemblies.

public string BaseDirectory { get; }
public string? BaseDirectory { get; }

Property Value

The base directory that the assembly resolver uses to probe for assemblies.

Implements

Exceptions

The operation is attempted on an unloaded application domain.

Examples

The following code example creates a new application domain, specifying a base directory to use when searching for assemblies to load into the domain. The example then uses the BaseDirectory property to obtain the base directory path, for display to the console.

using System;
using System.IO;
using System.Reflection;
using System.Security.Policy;

class ADSetupSnippet
{
    public static void Main()
    {
        // Create application domain setup information
        var domaininfo = new AppDomainSetup();
        domaininfo.ConfigurationFile = Path.Combine(System.Environment.CurrentDirectory, "ADSetup.exe.config");
        domaininfo.ApplicationBase = System.Environment.CurrentDirectory;

        //Create evidence for the new appdomain from evidence of the current application domain
        Evidence adEvidence = AppDomain.CurrentDomain.Evidence;

        // Create appdomain
        AppDomain domain = AppDomain.CreateDomain("Domain2", adEvidence, domaininfo);

        // Display application domain information.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("Child domain: " + domain.FriendlyName);
        Console.WriteLine();
        Console.WriteLine("Configuration file: " + domain.SetupInformation.ConfigurationFile);
        Console.WriteLine("Application Base Directory: " + domain.BaseDirectory);

        AppDomain.Unload(domain);
    }
}
// The example displays output like the following:
//    Host domain: adsetup.exe
//    Child domain: Domain2
//
//    Configuration file: C:\Test\ADSetup.exe.config
//    Application Base Directory: C:\Test

Remarks

This property corresponds to the AppDomainSetup.ApplicationBase property. It can also be retrieved using the GetData method with the string "APPBASE".

Applies to

Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also