通过


AppDomain 类

定义

表示应用程序域,这是应用程序执行的独立环境。 无法继承此类。

public ref class AppDomain sealed : MarshalByRefObject
public ref class AppDomain : MarshalByRefObject
public ref class AppDomain sealed : MarshalByRefObject, _AppDomain, System::Security::IEvidenceFactory
public sealed class AppDomain : MarshalByRefObject
public class AppDomain : MarshalByRefObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class AppDomain : MarshalByRefObject, _AppDomain, System.Security.IEvidenceFactory
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AppDomain : MarshalByRefObject, _AppDomain, System.Security.IEvidenceFactory
type AppDomain = class
    inherit MarshalByRefObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type AppDomain = class
    inherit MarshalByRefObject
    interface _AppDomain
    interface IEvidenceFactory
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type AppDomain = class
    inherit MarshalByRefObject
    interface _AppDomain
    interface IEvidenceFactory
Public NotInheritable Class AppDomain
Inherits MarshalByRefObject
Public Class AppDomain
Inherits MarshalByRefObject
Public NotInheritable Class AppDomain
Inherits MarshalByRefObject
Implements _AppDomain, IEvidenceFactory
继承
属性
实现

示例

此示例演示如何创建一个新 AppDomain类型,实例化该新 AppDomain类型,并与该类型的对象通信。 此外,此示例演示如何卸载 AppDomain 导致对象被垃圾回收。

using namespace System;
using namespace System::Reflection;
using namespace System::Threading;
using namespace System::Security::Policy;

// Because this class is derived from MarshalByRefObject, a proxy 
// to a MarshalByRefType object can be returned across an AppDomain 
// boundary.
ref class MarshalByRefType : MarshalByRefObject
{
public:
    //  Call this method via a proxy.
    void SomeMethod(String^ callingDomainName)
    {
        // Get this AppDomain's settings and display some of them.
        AppDomainSetup^ ads = AppDomain::CurrentDomain->SetupInformation;
        Console::WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}", 
            ads->ApplicationName, 
            ads->ApplicationBase, 
            ads->ConfigurationFile
        );

        // Display the name of the calling AppDomain and the name 
        // of the second domain.
        // NOTE: The application's thread has transitioned between 
        // AppDomains.
        Console::WriteLine("Calling from '{0}' to '{1}'.", 
            callingDomainName, 
            Thread::GetDomain()->FriendlyName
        );
    };
};

void main()
{
    // Get and display the friendly name of the default AppDomain.
    String^ callingDomainName = Thread::GetDomain()->FriendlyName;
    Console::WriteLine(callingDomainName);

    // Get and display the full name of the EXE assembly.
    String^ exeAssembly = Assembly::GetEntryAssembly()->FullName;
    Console::WriteLine(exeAssembly);

    // Construct and initialize settings for a second AppDomain.
    AppDomainSetup^ ads = gcnew AppDomainSetup();
    ads->ApplicationBase = AppDomain::CurrentDomain->BaseDirectory;

    ads->DisallowBindingRedirects = false;
    ads->DisallowCodeDownload = true;
    ads->ConfigurationFile = 
        AppDomain::CurrentDomain->SetupInformation->ConfigurationFile;

    // Create the second AppDomain.
    AppDomain^ ad2 = AppDomain::CreateDomain("AD #2", 
        AppDomain::CurrentDomain->Evidence, ads);

    // Create an instance of MarshalbyRefType in the second AppDomain. 
    // A proxy to the object is returned.
    MarshalByRefType^ mbrt = 
        (MarshalByRefType^) ad2->CreateInstanceAndUnwrap(
            exeAssembly, 
            MarshalByRefType::typeid->FullName
        );

    // Call a method on the object via the proxy, passing the 
    // default AppDomain's friendly name in as a parameter.
    mbrt->SomeMethod(callingDomainName);

    // Unload the second AppDomain. This deletes its object and 
    // invalidates the proxy object.
    AppDomain::Unload(ad2);
    try
    {
        // Call the method again. Note that this time it fails 
        // because the second AppDomain was unloaded.
        mbrt->SomeMethod(callingDomainName);
        Console::WriteLine("Sucessful call.");
    }
    catch(AppDomainUnloadedException^)
    {
        Console::WriteLine("Failed call; this is expected.");
    }
}

/* This code produces output similar to the following: 

AppDomainX.exe
AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
Calling from 'AppDomainX.exe' to 'AD #2'.
Failed call; this is expected.
 */
using System;
using System.Reflection;
using System.Threading;

class Module1
{
    public static void Main()
    {
        // Get and display the friendly name of the default AppDomain.
        string callingDomainName = Thread.GetDomain().FriendlyName;
        Console.WriteLine(callingDomainName);

        // Get and display the full name of the EXE assembly.
        string exeAssembly = Assembly.GetEntryAssembly().FullName;
        Console.WriteLine(exeAssembly);

        // Construct and initialize settings for a second AppDomain.
        AppDomainSetup ads = new AppDomainSetup();
        ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;

        ads.DisallowBindingRedirects = false;
        ads.DisallowCodeDownload = true;
        ads.ConfigurationFile =
            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

        // Create the second AppDomain.
        AppDomain ad2 = AppDomain.CreateDomain("AD #2", null, ads);

        // Create an instance of MarshalbyRefType in the second AppDomain.
        // A proxy to the object is returned.
        MarshalByRefType mbrt =
            (MarshalByRefType) ad2.CreateInstanceAndUnwrap(
                exeAssembly,
                typeof(MarshalByRefType).FullName
            );

        // Call a method on the object via the proxy, passing the
        // default AppDomain's friendly name in as a parameter.
        mbrt.SomeMethod(callingDomainName);

        // Unload the second AppDomain. This deletes its object and
        // invalidates the proxy object.
        AppDomain.Unload(ad2);
        try
        {
            // Call the method again. Note that this time it fails
            // because the second AppDomain was unloaded.
            mbrt.SomeMethod(callingDomainName);
            Console.WriteLine("Sucessful call.");
        }
        catch(AppDomainUnloadedException)
        {
            Console.WriteLine("Failed call; this is expected.");
        }
    }
}

// Because this class is derived from MarshalByRefObject, a proxy
// to a MarshalByRefType object can be returned across an AppDomain
// boundary.
public class MarshalByRefType : MarshalByRefObject
{
    //  Call this method via a proxy.
    public void SomeMethod(string callingDomainName)
    {
        // Get this AppDomain's settings and display some of them.
        AppDomainSetup ads = AppDomain.CurrentDomain.SetupInformation;
        Console.WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}",
            ads.ApplicationName,
            ads.ApplicationBase,
            ads.ConfigurationFile
        );

        // Display the name of the calling AppDomain and the name
        // of the second domain.
        // NOTE: The application's thread has transitioned between
        // AppDomains.
        Console.WriteLine("Calling from '{0}' to '{1}'.",
            callingDomainName,
            Thread.GetDomain().FriendlyName
        );
    }
}

/* This code produces output similar to the following:

AppDomainX.exe
AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
Calling from 'AppDomainX.exe' to 'AD #2'.
Failed call; this is expected.
 */
open System
open System.Reflection
open System.Threading

// Because this class is derived from MarshalByRefObject, a proxy
// to a MarshalByRefType object can be returned across an AppDomain
// boundary.
type MarshalByRefType() =
    inherit MarshalByRefObject()
    
    //  Call this method via a proxy.
    member _.SomeMethod(callingDomainName) =
        // Get this AppDomain's settings and display some of them.
        let ads = AppDomain.CurrentDomain.SetupInformation
        printfn $"AppName={ads.ApplicationName}, AppBase={ads.ApplicationBase}, ConfigFile={ads.ConfigurationFile}"

        // Display the name of the calling AppDomain and the name
        // of the second domain.
        // NOTE: The application's thread has transitioned between
        // AppDomains.
        printfn $"Calling from '{callingDomainName}' to '{Thread.GetDomain().FriendlyName}'."

// Get and display the friendly name of the default AppDomain.
let callingDomainName = Thread.GetDomain().FriendlyName
printfn $"{callingDomainName}"

// Get and display the full name of the EXE assembly.
let exeAssembly = Assembly.GetEntryAssembly().FullName
printfn $"{exeAssembly}"

// Construct and initialize settings for a second AppDomain.
let ads = AppDomainSetup()
ads.ApplicationBase <- AppDomain.CurrentDomain.BaseDirectory

ads.DisallowBindingRedirects <- false
ads.DisallowCodeDownload <- true
ads.ConfigurationFile <-
    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

// Create the second AppDomain.
let ad2 = AppDomain.CreateDomain("AD #2", null, ads)

// Create an instance of MarshalbyRefType in the second AppDomain.
// A proxy to the object is returned.
let mbrt =
    ad2.CreateInstanceAndUnwrap(
        exeAssembly,
        typeof<MarshalByRefType>.FullName) :?> MarshalByRefType

// Call a method on the object via the proxy, passing the
// default AppDomain's friendly name in as a parameter.
mbrt.SomeMethod callingDomainName

// Unload the second AppDomain. This deletes its object and
// invalidates the proxy object.
AppDomain.Unload ad2
try
    // Call the method again. Note that this time it fails
    // because the second AppDomain was unloaded.
    mbrt.SomeMethod callingDomainName
    printfn "Sucessful call."
with :? AppDomainUnloadedException ->
    printfn "Failed call this is expected."

(* This code produces output similar to the following:

AppDomainX.exe
AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
Calling from 'AppDomainX.exe' to 'AD #2'.
Failed call this is expected.
 *)
Imports System.Reflection
Imports System.Threading

Module Module1
    Sub Main()

        ' Get and display the friendly name of the default AppDomain.
        Dim callingDomainName As String = Thread.GetDomain().FriendlyName
        Console.WriteLine(callingDomainName)

        ' Get and display the full name of the EXE assembly.
        Dim exeAssembly As String = [Assembly].GetEntryAssembly().FullName
        Console.WriteLine(exeAssembly)

        ' Construct and initialize settings for a second AppDomain.
        Dim ads As New AppDomainSetup()
        ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
        ads.DisallowBindingRedirects = False
        ads.DisallowCodeDownload = True
        ads.ConfigurationFile = _
            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

        ' Create the second AppDomain.
        Dim ad2 As AppDomain = AppDomain.CreateDomain("AD #2", Nothing, ads)

        ' Create an instance of MarshalbyRefType in the second AppDomain. 
        ' A proxy to the object is returned.
        Dim mbrt As MarshalByRefType = CType( _
            ad2.CreateInstanceAndUnwrap(exeAssembly, _
                 GetType(MarshalByRefType).FullName), MarshalByRefType)

        ' Call a method on the object via the proxy, passing the default 
        ' AppDomain's friendly name in as a parameter.
        mbrt.SomeMethod(callingDomainName)

        ' Unload the second AppDomain. This deletes its object and 
        ' invalidates the proxy object.
        AppDomain.Unload(ad2)
        Try
            ' Call the method again. Note that this time it fails because 
            ' the second AppDomain was unloaded.
            mbrt.SomeMethod(callingDomainName)
            Console.WriteLine("Sucessful call.")
        Catch e As AppDomainUnloadedException
            Console.WriteLine("Failed call; this is expected.")
        End Try

    End Sub
End Module

' Because this class is derived from MarshalByRefObject, a proxy 
' to a MarshalByRefType object can be returned across an AppDomain 
' boundary.
Public Class MarshalByRefType
    Inherits MarshalByRefObject

    '  Call this method via a proxy.
    Public Sub SomeMethod(ByVal callingDomainName As String)

        ' Get this AppDomain's settings and display some of them.
        Dim ads As AppDomainSetup = AppDomain.CurrentDomain.SetupInformation
        Console.WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}", _
            ads.ApplicationName, ads.ApplicationBase, ads.ConfigurationFile)

        ' Display the name of the calling AppDomain and the name 
        ' of the second domain.
        ' NOTE: The application's thread has transitioned between 
        ' AppDomains.
        Console.WriteLine("Calling from '{0}' to '{1}'.", _
            callingDomainName, Thread.GetDomain().FriendlyName)
    End Sub
End Class

'This code produces output similar to the following:
' 
' AppDomainX.exe
' AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
' AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
' Calling from 'AppDomainX.exe' to 'AD #2'.
' Failed call; this is expected.

注解

应用程序域(由 AppDomain 对象表示)有助于提供隔离、卸载和安全边界来执行托管代码。

  • 使用应用程序域隔离可能会降低进程的任务。 如果正在执行任务的状态 AppDomain 变得不稳定,则可以卸载该 AppDomain 任务,而不会影响进程。 当进程必须长时间运行而不重启时,这一点很重要。 还可以使用应用程序域来隔离不应共享数据的任务。
  • 如果将程序集加载到默认应用程序域中,则进程运行时无法从内存中卸载该程序集。 但是,如果打开第二个应用程序域来加载和执行程序集,则在卸载该应用程序域时会卸载该程序集。 使用此方法可以最大程度地减少偶尔使用大型 DLL 的长时间运行的进程集。

注释

在 .NET Core 和 .NET 5+ 上,实现 AppDomain 受设计限制,不提供隔离、卸载或安全边界。 这些版本只有一个 AppDomain。 隔离和卸载通过 AssemblyLoadContext提供。 安全边界应由进程边界和适当的远程处理技术提供。

多个应用程序域可以在单个进程中运行;但是,应用程序域和线程之间没有一对一关联。 多个线程可以属于单个应用程序域,而给定线程在任何给定时间都不会局限于单个应用程序域,但线程在单个应用程序域中执行。

应用程序域是使用 CreateDomain 该方法创建的。 AppDomain 实例用于加载和执行程序集(Assembly)。 当不再使用时 AppDomain ,可以卸载它。

AppDomain 类实现一组事件,使应用程序能够在加载程序集、卸载应用程序域时或引发未经处理的异常时响应。

有关使用应用程序域的详细信息,请参阅 应用程序域

此类实现 MarshalByRefObject接口 _AppDomainIEvidenceFactory 接口。

不应为 AppDomain 对象创建可远程包装器。 这样做可能会发布对该 AppDomain对象的远程引用,从而公开远程访问等 CreateInstance 方法,并有效地破坏该 AppDomain代码访问安全性。 连接到远程 AppDomain 的恶意客户端可以获取对自身有权访问的任何资源 AppDomain 的访问权限。 不要为任何扩展 MarshalByRefObject 和实现恶意客户端可用于绕过安全系统的方法的类型创建可远程包装器。

注意

AppDomainSetup.DisallowCodeDownload 属性的默认值是 false。 此设置对服务不安全。 若要防止服务下载部分受信任的代码,请将此属性设置为 true

属性

名称 说明
ActivationContext

获取当前应用程序域的激活上下文。

ApplicationIdentity

获取应用程序域中应用程序的标识。

ApplicationTrust

获取描述授予应用程序的权限以及应用程序是否具有允许其运行的信任级别的信息。

BaseDirectory

获取程序集解析程序用于探测程序集的基目录。

CurrentDomain

获取当前应用程序的当前 Thread域。

DomainManager

获取初始化应用程序域时主机提供的域管理器。

DynamicDirectory

获取程序集解析程序用于探测动态创建的程序集的目录。

Evidence

Evidence获取与此应用程序域关联的值。

FriendlyName

获取此应用程序域的友好名称。

Id

获取一个整数,该整数唯一标识进程中的应用程序域。

IsFullyTrusted

获取一个值,该值指示加载到当前应用程序域中的程序集是否完全信任执行。

IsHomogenous

获取一个值,该值指示当前应用程序域是否具有向加载到应用程序域的所有程序集授予的一组权限。

MonitoringIsEnabled

获取或设置一个值,该值指示是否为当前进程启用应用程序域的 CPU 和内存监视。 为进程启用监视后,无法禁用它。

MonitoringSurvivedMemorySize

获取在最后一个集合中幸存下来的字节数,以及已知由当前应用程序域引用的字节数。

MonitoringSurvivedProcessMemorySize

获取从进程中所有应用程序域的最后一个集合中幸存下来的总字节数。

MonitoringTotalAllocatedMemorySize

获取自创建应用程序域以来由应用程序域进行的所有内存分配的总大小(以字节为单位)而不减去已收集的内存。

MonitoringTotalProcessorTime

获取自进程启动以来,在当前应用程序域中执行时所有线程使用的总处理器时间。

PermissionSet
已过时.

获取沙盒应用程序域的权限集。

RelativeSearchPath

获取基目录下的路径,其中程序集解析程序应探测专用程序集。

SetupInformation

获取此实例的应用程序域配置信息。

ShadowCopyFiles

获取一个指示应用程序域是否配置为卷影复制文件。

方法

名称 说明
AppendPrivatePath(String)
已过时.
已过时.
已过时.

将指定的目录名称追加到专用路径列表中。

ApplyPolicy(String)

在应用策略后返回程序集显示名称。

ClearPrivatePath()
已过时.
已过时.
已过时.

将指定专用程序集的位置的路径重置为空字符串(“)。

ClearShadowCopyPath()
已过时.
已过时.
已过时.

将包含卷影复制程序集的目录列表重置为空字符串(“)。

CreateComInstanceFrom(String, String, Byte[], AssemblyHashAlgorithm)

创建指定 COM 类型的新实例。 参数指定包含包含类型和类型名称的程序集的文件的名称。

CreateComInstanceFrom(String, String)

创建指定 COM 类型的新实例。 参数指定包含包含类型和类型名称的程序集的文件的名称。

CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])

使用指定的名称、证据、应用程序域设置信息、默认权限集和完全受信任的程序集数组创建新的应用程序域。

CreateDomain(String, Evidence, AppDomainSetup)

使用指定的名称、证据和应用程序域设置信息创建新的应用程序域。

CreateDomain(String, Evidence, String, String, Boolean, AppDomainInitializer, String[])

使用证据、应用程序基路径、相对搜索路径和参数创建具有给定名称的新应用程序域,该参数指定程序集的卷影副本是否要加载到应用程序域中。 指定在初始化应用程序域时调用的回调方法,以及传递回调方法的字符串参数数组。

CreateDomain(String, Evidence, String, String, Boolean)

使用证据、应用程序基路径、相对搜索路径和参数创建具有给定名称的新应用程序域,该参数指定程序集的卷影副本是否要加载到应用程序域中。

CreateDomain(String, Evidence)

使用提供的证据创建具有给定名称的新应用程序域。

CreateDomain(String)
已过时.

创建具有指定名称的新应用程序域。

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

创建指定程序集中定义的指定类型的新实例。 参数指定绑定器、绑定标志、构造函数参数、用于解释参数、激活属性和创建类型的授权的特定于区域性的信息。

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

创建指定程序集中定义的指定类型的新实例。 参数指定绑定器、绑定标志、构造函数参数、用于解释参数的区域性特定信息以及可选的激活属性。

CreateInstance(String, String, Object[])

创建指定程序集中定义的指定类型的新实例。 参数指定激活属性数组。

CreateInstance(String, String)

创建指定程序集中定义的指定类型的新实例。

CreateInstanceAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

创建指定类型的新实例。 参数指定类型的名称及其创建方式。

CreateInstanceAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

创建指定程序集中定义的指定类型的新实例,指定是否忽略类型名称大小写;用于选择要创建的类型的绑定属性和绑定器;构造函数的参数;区域性;和激活属性。

CreateInstanceAndUnwrap(String, String, Object[])

创建指定类型的新实例。 参数指定在其中定义类型的程序集、类型的名称和激活属性数组。

CreateInstanceAndUnwrap(String, String)

创建指定类型的新实例。 参数指定在其中定义类型的程序集以及类型的名称。

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFrom(String, String, Object[])

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFrom(String, String)

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFromAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFromAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

创建指定程序集文件中定义的指定类型的新实例,指定是否忽略类型名称大小写;用于选择要创建的类型的绑定属性和绑定器;构造函数的参数;区域性;和激活属性。

CreateInstanceFromAndUnwrap(String, String, Object[])

创建指定程序集文件中定义的指定类型的新实例。

CreateInstanceFromAndUnwrap(String, String)

创建指定程序集文件中定义的指定类型的新实例。

CreateObjRef(Type)

创建一个对象,其中包含生成用于与远程对象通信的代理所需的所有相关信息。

(继承自 MarshalByRefObject)
DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
已过时.

使用指定的名称、访问模式、证据和权限请求定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, Evidence)
已过时.

使用指定的名称、访问模式和证据定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>, SecurityContextSource)

定义具有指定名称、访问模式和自定义属性的动态程序集,并使用指定源作为其安全上下文。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)

定义具有指定名称、访问模式和自定义属性的动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
已过时.

使用指定的名称、访问模式和权限请求定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>)

使用指定的名称、访问模式、存储目录和同步选项定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
已过时.

定义具有指定名称、访问模式、存储目录、证据、权限请求、同步选项和自定义属性的动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
已过时.

使用指定的名称、访问模式、存储目录、证据、权限请求和同步选项定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
已过时.

使用指定的名称、访问模式、存储目录、证据和权限请求定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence)
已过时.

使用指定的名称、访问模式、存储目录和证据定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
已过时.

使用指定的名称、访问模式、存储目录和权限请求定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String)

使用指定的名称、访问模式和存储目录定义动态程序集。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)

定义具有指定名称和访问模式的动态程序集。

DoCallBack(CrossAppDomainDelegate)

在由指定委托标识的另一个应用程序域中执行代码。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm)
已过时.

使用指定的证据、参数、哈希值和哈希算法执行指定文件中包含的程序集。

ExecuteAssembly(String, Evidence, String[])
已过时.

使用指定的证据和参数执行指定文件中包含的程序集。

ExecuteAssembly(String, Evidence)
已过时.

使用指定的证据执行指定文件中包含的程序集。

ExecuteAssembly(String, String[], Byte[], AssemblyHashAlgorithm)
已过时.

使用指定的参数、哈希值和哈希算法执行指定文件中包含的程序集。

ExecuteAssembly(String, String[])

使用指定的参数执行指定文件中包含的程序集。

ExecuteAssembly(String)

执行指定文件中包含的程序集。

ExecuteAssemblyByName(AssemblyName, Evidence, String[])
已过时.

使用指定的证据和参数执行给定 AssemblyName的程序集。

ExecuteAssemblyByName(AssemblyName, String[])

使用指定的参数执行给定 AssemblyName的程序集。

ExecuteAssemblyByName(String, Evidence, String[])
已过时.

使用指定的证据和参数执行给定其显示名称的程序集。

ExecuteAssemblyByName(String, Evidence)
已过时.

使用指定的证据执行给定其显示名称的程序集。

ExecuteAssemblyByName(String, String[])

使用指定的参数执行给定其显示名称的程序集。

ExecuteAssemblyByName(String)

执行给定其显示名称的程序集。

GetAssemblies()

获取已加载到此应用程序域的执行上下文中的程序集。

GetCurrentThreadId()
已过时.
已过时.
已过时.
已过时.

获取当前线程标识符。

GetData(String)

获取存储在指定名称的当前应用程序域中的值。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetType()

获取当前实例的类型。

GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()

通过阻止创建租约来 AppDomain 提供无限生存期。

InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
IsCompatibilitySwitchSet(String)

获取一个可为 null 的布尔值,该值指示是否设置了任何兼容性开关,如果是,则是否设置指定的兼容性开关。

IsDefaultAppDomain()

返回一个值,该值指示应用程序域是否是进程的默认应用程序域。

IsFinalizingForUnload()

指示此应用程序域是否正在卸载,以及它包含的对象正在由公共语言运行时完成。

Load(AssemblyName, Evidence)
已过时.

加载给定 Assembly 的 . AssemblyName.

Load(AssemblyName)

加载给定 Assembly 的 . AssemblyName.

Load(Byte[], Byte[], Evidence)
已过时.

Assembly加载包含所发出的Assembly通用对象文件格式(COFF)的图像。 还将加载表示符号 Assembly 的原始字节。

Load(Byte[], Byte[])

Assembly加载包含所发出的Assembly通用对象文件格式(COFF)的图像。 还将加载表示符号 Assembly 的原始字节。

Load(Byte[])

Assembly加载包含所发出的Assembly通用对象文件格式(COFF)的图像。

Load(String, Evidence)
已过时.

加载给定 Assembly 的显示名称。

Load(String)

加载给定 Assembly 的显示名称。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ReflectionOnlyGetAssemblies()

返回已加载到应用程序域的仅反射上下文中的程序集。

SetAppDomainPolicy(PolicyLevel)
已过时.

为此应用程序域建立安全策略级别。

SetCachePath(String)
已过时.
已过时.
已过时.

将指定的目录路径建立为复制程序集的位置。

SetData(String, Object, IPermission)

向指定的应用程序域属性分配指定值,在检索属性时,具有对调用方要求的指定权限。

SetData(String, Object)

将指定的值分配给指定的应用程序域属性。

SetDynamicBase(String)
已过时.
已过时.
已过时.

将指定的目录路径建立为存储并访问动态生成的文件的子目录的基目录。

SetPrincipalPolicy(PrincipalPolicy)

指定当线程尝试在此应用程序域中执行时绑定到主体时,应如何将主体和标识对象附加到线程。

SetShadowCopyFiles()
已过时.
已过时.
已过时.

打开卷影复制。

SetShadowCopyPath(String)
已过时.
已过时.
已过时.

将指定的目录路径建立为要复制卷影的程序集的位置。

SetThreadPrincipal(IPrincipal)

设置要附加到线程的默认主体对象(如果在此应用程序域中执行时尝试绑定到主体)。

ToString()

获取包含应用程序域的友好名称和任何上下文策略的字符串表示形式。

Unload(AppDomain)
已过时.

卸载指定的应用程序域。

活动

名称 说明
AssemblyLoad

加载程序集时发生。

AssemblyResolve

在程序集解析失败时发生。

DomainUnload

即将卸载时 AppDomain 发生。

FirstChanceException

在托管代码中引发异常时发生,运行时在应用程序域中搜索异常处理程序的调用堆栈之前。

ProcessExit

在默认应用程序域的父进程退出时发生。

ReflectionOnlyAssemblyResolve

当程序集解析在仅反射上下文中失败时发生。

ResourceResolve

当资源解析失败时发生,因为资源不是程序集中的有效链接资源或嵌入资源。

TypeResolve

当类型解析失败时发生。

UnhandledException

未捕获异常时发生。

显式接口实现

名称 说明
_AppDomain.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

_AppDomain.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

_AppDomain.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

_AppDomain.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对对象公开的属性和方法的访问。

适用于

另请参阅