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

方法描述

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

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

[ObsoleteAttribute("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssembly which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public int ExecuteAssembly(
	string assemblyFile,
	Evidence assemblySecurity,
	string[] args,
	byte[] hashValue,
	AssemblyHashAlgorithm hashAlgorithm
)

参数/返回值

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

提示和注释

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

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

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

System.AppDomain.ExecuteAssembly 方法 (String, Evidence, 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 不是有效程序集。
  • 当前加载的是 2.0 或更高版本的公共语言运行时,assemblyFile 是用更高版本的公共语言运行时编译的。
AppDomainUnloadedException 尝试对已卸载的应用程序域进行操作。
FileLoadException 用两个不同的证据将一个程序集或模块加载了两次。
NotSupportedException assemblySecurity 不是 null。 未启用旧版 CAS 策略时,assemblySecurity 应该为 null。
MissingMethodException 指定的程序集无入口点。

命名空间

namespace: System

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

版本信息

.NET Framework 受以下版本支持:3.5、3.0、2.0、1.1 在 4 中过时(编译器警告) .NET Framework Client Profile 受以下版本支持:3.5 SP1 在 4 中过时(编译器警告)

适用平台

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 系统要求。