AppDomainSetup.ApplicationBase Property

Definition

Gets the name of the directory containing the application.

C#
public string? ApplicationBase { get; }
C#
public string ApplicationBase { get; set; }

Property Value

The name of the application base directory.

Implements

Examples

The following example demonstrates how to use the ApplicationBase property to set the location where the assembly loader begins probing for assemblies to load into a new application domain.

Note

You must ensure that the folder you specify exists.

C#
using System;

class ADSetupInformation
{
    static void Main()
    {
        AppDomain root = AppDomain.CurrentDomain;

        AppDomainSetup setup = new AppDomainSetup();
        setup.ApplicationBase =
            root.SetupInformation.ApplicationBase + @"MyAppSubfolder\";

        AppDomain domain = AppDomain.CreateDomain("MyDomain", null, setup);

        Console.WriteLine("Application base of {0}:\r\n\t{1}",
            root.FriendlyName, root.SetupInformation.ApplicationBase);
        Console.WriteLine("Application base of {0}:\r\n\t{1}",
            domain.FriendlyName, domain.SetupInformation.ApplicationBase);

        AppDomain.Unload(domain);
    }
}

/* This example produces output similar to the following:

Application base of MyApp.exe:
        C:\Program Files\MyApp\
Application base of MyDomain:
        C:\Program Files\MyApp\MyAppSubfolder\
 */

Remarks

The application base directory is where the assembly manager begins probing for assemblies.

The ApplicationBase property can influence which permissions are granted to an application domain. For example, an application domain originating from the local computer normally receives full trust based on its location of origin. However, if the ApplicationBase property of that AppDomain is set to the full name of an intranet directory, the ApplicationBase setting restricts the permissions granted to the application domain to a LocalIntranet grant even though the application domain actually originates from the local computer.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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