AppDomain.GetAssemblies 方法

定义

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

public System.Reflection.Assembly[] GetAssemblies ();

返回

Assembly[]

此应用程序域中的程序集的数组。

实现

例外

在卸载的应用程序域上尝试该操作。

示例

下面的代码示例使用 GetAssemblies 该方法获取已加载到应用程序域的所有程序集的列表。 然后,程序集会显示到控制台。

若要运行此代码示例,需要创建一 CustomLibrary.dll个名为的程序集,或更改传递给该方法的 GetAssemblies 程序集名称。

using System;
using System.Reflection;
using System.Security.Policy;

class ADGetAssemblies
{

    public static void Main()
    {
        AppDomain currentDomain = AppDomain.CurrentDomain;
        //Provide the current application domain evidence for the assembly.
        Evidence asEvidence = currentDomain.Evidence;
        //Load the assembly from the application directory using a simple name.

        //Create an assembly called CustomLibrary to run this sample.
        currentDomain.Load("CustomLibrary",asEvidence);

        //Make an array for the list of assemblies.
        Assembly[] assems = currentDomain.GetAssemblies();
    
        //List the assemblies in the current application domain.
        Console.WriteLine("List of assemblies loaded in current appdomain:");
            foreach (Assembly assem in assems)
                Console.WriteLine(assem.ToString());
    }
}

适用于