AppDomainManager.InitializeNewDomain(AppDomainSetup) AppDomainManager.InitializeNewDomain(AppDomainSetup) AppDomainManager.InitializeNewDomain(AppDomainSetup) AppDomainManager.InitializeNewDomain(AppDomainSetup) Method


初始化新应用程序域。Initializes the new application domain.

 virtual void InitializeNewDomain(AppDomainSetup ^ appDomainInfo);
public virtual void InitializeNewDomain (AppDomainSetup appDomainInfo);
abstract member InitializeNewDomain : AppDomainSetup -> unit
override this.InitializeNewDomain : AppDomainSetup -> unit
Public Overridable Sub InitializeNewDomain (appDomainInfo As AppDomainSetup)


AppDomainSetup AppDomainSetup AppDomainSetup AppDomainSetup

包含应用程序域初始化信息的对象。An object that contains application domain initialization information.


下面的示例演示了对自定义InitializeNewDomain应用程序域管理器的方法的重写。The following example shows an override of the InitializeNewDomain method for a custom application domain manager. 此代码示例是为AppDomainManager类提供的更大示例的一部分。This code example is part of a larger example provided for the AppDomainManager class.

public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
    Console.Write("Initialize new domain called:  ");
    InitializationFlags = 
Public Overrides Sub InitializeNewDomain(ByVal appDomainInfo _
    As AppDomainSetup) 
    Console.Write("Initialize new domain called:  ")
    InitializationFlags = _
End Sub



不要使用此方法初始化 ASP.NET 中的应用程序域。Do not use this method to initialize an application domain in ASP.NET. 在 ASP.NET 中, 必须由主机处理配置。In ASP.NET, configuration must be handled by the host. 如果使用此方法初始化应用程序域, 则在尝试初始化应用InvalidOperationException程序域时, 主机将引发。If you use this method to initialize the application domain, the host throws InvalidOperationException when it attempts to initialize the application domain. 异常消息指示已进行了初始化。The exception message indicates that initialization has already occurred.

此方法在构造函数之后立即调用。This method is called immediately after the constructor. 默认InitializeNewDomain实现不执行任何操作。The default InitializeNewDomain implementation does nothing. 自定义实现可以设置内部类和委托, 设置具有非托管主机接口的接口, 或设置新AppDomain的事件处理程序。A custom implementation can set up internal classes and delegates, set up an interface with the unmanaged host interface, or set up event handlers for the new AppDomain.

此外, 对于外接程序激活, 自定义实现可将当前AppDomain标识为目标应用程序域。Also, for add-in activations, a custom implementation could identify the current AppDomain as the target application domain.

从开始, 可以使用此方法在应用程序启动时将默认应用程序域沙盒, 或修改新应用程序域的沙箱。 .NET Framework 4.NET Framework 4Beginning with the .NET Framework 4.NET Framework 4, you can use this method to sandbox the default application domain at application startup, or to modify the sandbox of a new application domain. 为此, 请在初始化DefaultGrantSet应用FullTrustAssemblies程序域之前ApplicationTrust , 调整分配给AppDomainSetup.ApplicationTrust的属性appDomainInfo的对象的和属性。To do this, adjust the DefaultGrantSet and FullTrustAssemblies properties on the ApplicationTrust object that is assigned to the AppDomainSetup.ApplicationTrust property of appDomainInfo, before you initialize the application domain.


FullTrust授予的程序集 (例如全局程序集缓存中的程序集fullTrustAssemblies或在AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])方法中标识为的程序AppDomainManager集) InitializeNewDomain可以在构造函数和方法中加载。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.