System.AppDomain.ExecuteAssembly 方法 (String, String[], Byte[], AssemblyHashAlgorithm)

方法描述

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

语法定义(C# System.AppDomain.ExecuteAssembly 方法 (String, String[], Byte[], AssemblyHashAlgorithm) 的用法)

public int ExecuteAssembly(
	string assemblyFile,
	string[] args,
	byte[] hashValue,
	AssemblyHashAlgorithm hashAlgorithm
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
assemblyFile System-String 包含要执行程序集的文件的名称。
args System-String[] 程序集的入口点的实参。
hashValue System-Byte[] 表示计算所得的哈希代码的值。
hashAlgorithm System-Configuration-Assemblies-AssemblyHashAlgorithm 表示程序集清单使用的哈希算法。
返回值 System.Int32 程序集的入口点返回的值。

提示和注释

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

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

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

System.AppDomain.ExecuteAssembly 方法 (String, String[], Byte[], AssemblyHashAlgorithm)例子

下面的示例演示如何对两个不同的域使用 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 不是有效程序集。
  • assemblyFile 使用比当前加载的版本更高的公共语言运行时版本编译的。
AppDomainUnloadedException 尝试对已卸载的应用程序域进行操作。
FileLoadException 用两个不同的证据将一个程序集或模块加载了两次。
MissingMethodException 指定的程序集无入口点。

命名空间

namespace: System

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

版本信息

.NET Framework 受以下版本支持:4 .NET Framework Client Profile 受以下版本支持:4

适用平台

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