AppDomainManager Class

Provides a managed equivalent of an unmanaged host.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public class AppDomainManager : MarshalByRefObject
/** @attribute ComVisibleAttribute(true) */ 
public class AppDomainManager extends MarshalByRefObject
public class AppDomainManager extends MarshalByRefObject
Not applicable.


Do not use AppDomainManager to configure an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host.

Implementing the AppDomainManager class enables a hosting application to participate in the creation of new application domains. To replace the default AppDomainManager, identify the assembly and type of the replacement AppDomainManager in the APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE environment variables. The assembly must be fully trusted and be contained in the global assembly cache or the directory of the starting application. The type and assembly names must be fully qualified in the environment variables. For example:

set APPDOMAIN_MANAGER_TYPE=MyNamespace.TestAppDomainManager

set APPDOMAIN_MANAGER_ASM=customappDomainmanager, Version=, Culture=neutral, PublicKeyToken=f1368f7b12a08d72

The AppDomainManager is the managed equivalent of the unmanaged host. An AppDomainManager object participates in the creation of new application domains in a process and can customize the new AppDomain before other managed code runs. The AppDomainManager can also supply host managers that participate in other aspects of common language runtime execution. For example, an AppDomainManager can identify a HostSecurityManager object that participates in the security decisions of theapplication domain.


Only assemblies granted FullTrust, such as assemblies in the global assembly cache or identified as fullTrustAssemblies in the AppDomain.CreateDomain(String,Evidence,AppDomainSetup,PermissionSet,StrongName[]) method can be loaded in the AppDomainManager constructor and the InitializeNewDomain method.


This class contains a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

The following code example shows a very simple implementation of AppDomainManager.

// To replace the default AppDomainManager, identify  the 
// replacement assembly and replacement type in the 
// environment variables. For example:
// set APPDOMAIN_MANAGER_TYPE=library.TestAppDomainManager
// set APPDOMAIN_MANAGER_ASM=library, Version=, Culture=neutral, PublicKeyToken=f1368f7b12a08d72

using System;
using System.Collections;
using System.Net;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Threading;
using System.Runtime.InteropServices;

[assembly: System.Security.AllowPartiallyTrustedCallersAttribute()]

namespace MyNamespace
        Flags = SecurityPermissionFlag.Infrastructure)]
        Flags = SecurityPermissionFlag.Infrastructure)]
    public class MyAppDomainManager : AppDomainManager
        private HostSecurityManager mySecurityManager = null;

        public MyAppDomainManager()
            Console.WriteLine(" My AppDomain Manager ");
            mySecurityManager = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
                "CustomSecurityManager, Version=, Culture=neutral, " +
                "MyNamespace.MySecurityManager") as HostSecurityManager;
            Console.WriteLine(" Custom Security Manager Created.");

        public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
            Console.Write("Initialize new domain called:  ");
            InitializationFlags = 

        public override HostSecurityManager HostSecurityManager
                return mySecurityManager;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

XNA Framework

Supported in: 1.0