[C#] Application Domains

In .NET, a process does not manage assemblies directly. There is an additional logical layer called an application domain. An application domain is an isolated environment where applications execute and it is represented by the “System.AppDomain” class.

1. System.AppDomain

The key properties are:

  • string BaseDirectory { get; }
  • string FriendlyName { get; }
  • int Id { get; }
  • AppDomainSetup SetupInformation { get; }

2. Getting the Current Application Domain

The static “CurrentDomain” property is used to get a current application domain.

  • public static AppDomain CurrentDomain { get; }
AppDomain domain = AppDomain.CurrentDomain;
Console.WriteLine("{0}: {1}, {2}", domain.Id, domain.FriendlyName, domain.BaseDirectory);

3. Enumerating Loaded Assemblies

You can get a list of assemblies loaded by the application domain using the “GetAssemblies()” method.

  • public System.Reflection.Assembly[] GetAssemblies()
AppDomain domain = AppDomain.CurrentDomain;
foreach(Assembly a in domain.GetAssemblies())

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s