System.AppDomain.ExecuteAssembly 方法 (String)

方法描述

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

语法定义(C# System.AppDomain.ExecuteAssembly 方法 (String) 的用法)

public int ExecuteAssembly(
	string assemblyFile
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
assemblyFile System-String 包含要执行程序集的文件的名称。
返回值 System.Int32 程序集的入口点返回的值。

提示和注释

程序集从 .NET Framework 标头中指定的入口点处开始执行。

此方法不创建新的进程或应用程序域,并且不在新线程上执行入口点方法。

此方法使用 LoadFile 方法加载程序集。 还可以使用 ExecuteAssemblyByName 方法执行程序集,该方法使用 Load 方法加载程序集。

若要创建要加载和执行的 AppDomain,请使用 CreateDomain 方法。

System.AppDomain.ExecuteAssembly 方法 (String)例子

下面的示例演示如何对两个不同的域使用 ExecuteAssembly 的重载之一。

class Test {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");

      currentDomain.ExecuteAssembly("MyExecutable.exe");
      // Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe");
      // Prints "MyExecutable running on otherDomain"
   }
}

异常

异常 异常描述
ArgumentNullException assemblyFile 为 null。
FileNotFoundException 未找到 assemblyFile。
BadImageFormatException
  • assemblyFile 不是有效程序集。
  • 当前加载的是 2.0 或更高版本的公共语言运行时,assemblyFile 是用更高版本的公共语言运行时编译的。
AppDomainUnloadedException 尝试对已卸载的应用程序域进行操作。
FileLoadException 用两个不同的证据将一个程序集或模块加载了两次。
MissingMethodException 指定的程序集无入口点。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。