AppDomain.ExecuteAssembly AppDomain.ExecuteAssembly AppDomain.ExecuteAssembly AppDomain.ExecuteAssembly Method

定义

执行指定文件中包含的程序集。Executes the assembly contained in the specified file.

重载

ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm)

使用指定的证据、参数、哈希值和哈希算法执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence, arguments, hash value, and hash algorithm.

ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[])

使用指定的证据和自变量执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence and arguments.

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

使用指定的参数、哈希值和哈希算法执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified arguments, hash value, and hash algorithm.

ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence)

使用指定的证据执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence.

ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[])

使用指定的参数执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified arguments.

ExecuteAssembly(String) ExecuteAssembly(String) ExecuteAssembly(String) ExecuteAssembly(String)

执行指定文件中包含的程序集。Executes the assembly contained in the specified file.

ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm) ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm)

警告

此 API 现已过时。

使用指定的证据、参数、哈希值和哈希算法执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence, arguments, hash value, and hash algorithm.

public:
 int ExecuteAssembly(System::String ^ assemblyFile, System::Security::Policy::Evidence ^ assemblySecurity, cli::array <System::String ^> ^ args, cli::array <System::Byte> ^ hashValue, System::Configuration::Assemblies::AssemblyHashAlgorithm hashAlgorithm);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("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, System.Security.Policy.Evidence assemblySecurity, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
member this.ExecuteAssembly : string * System.Security.Policy.Evidence * string[] * byte[] * System.Configuration.Assemblies.AssemblyHashAlgorithm -> int
Public Function ExecuteAssembly (assemblyFile As String, assemblySecurity As Evidence, args As String(), hashValue As Byte(), hashAlgorithm As AssemblyHashAlgorithm) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

assemblySecurity
Evidence Evidence Evidence Evidence

为程序集提供的证据。The supplied evidence for the assembly.

args
String[]

程序集的入口点的实参。The arguments to the entry point of the assembly.

hashValue
Byte[]

表示计算所得的哈希代码的值。Represents the value of the computed hash code.

hashAlgorithm
AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm

表示程序集清单使用的哈希算法。Represents the hash algorithm used by the assembly manifest.

返回

程序集的入口点返回的值。The value returned by the entry point of the assembly.

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyFile 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

assemblySecurity 不是 nullassemblySecurity is not null. 未启用旧版 CAS 策略时,assemblySecurity 应为 nullWhen legacy CAS policy is not enabled, assemblySecurity should be null.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

此方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

安全性

SecurityPermission
若要使用的证据加载程序集。to load an assembly with evidence. 关联枚举: ControlEvidenceAssociated enumeration: ControlEvidence.

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[]) ExecuteAssembly(String, Evidence, String[])

警告

此 API 现已过时。

使用指定的证据和自变量执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence and arguments.

public:
 virtual int ExecuteAssembly(System::String ^ assemblyFile, System::Security::Policy::Evidence ^ assemblySecurity, cli::array <System::String ^> ^ args);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("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, System.Security.Policy.Evidence assemblySecurity, string[] args);
abstract member ExecuteAssembly : string * System.Security.Policy.Evidence * string[] -> int
override this.ExecuteAssembly : string * System.Security.Policy.Evidence * string[] -> int
Public Function ExecuteAssembly (assemblyFile As String, assemblySecurity As Evidence, args As String()) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

assemblySecurity
Evidence Evidence Evidence Evidence

为程序集提供的证据。The supplied evidence for the assembly.

args
String[]

程序集的入口点的实参。The arguments to the entry point of the assembly.

返回

程序集的入口点返回的值。The value returned by the entry point of the assembly.

实现

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyFile 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

assemblySecurity 不是 nullassemblySecurity is not null. 未启用旧版 CAS 策略时,assemblySecurity 应为 nullWhen legacy CAS policy is not enabled, assemblySecurity should be null.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

此方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

安全性

SecurityPermission
若要使用的证据加载程序集。to load an assembly with evidence. 关联枚举: ControlEvidenceAssociated enumeration: ControlEvidence.

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

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

使用指定的参数、哈希值和哈希算法执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified arguments, hash value, and hash algorithm.

public:
 int ExecuteAssembly(System::String ^ assemblyFile, cli::array <System::String ^> ^ args, cli::array <System::Byte> ^ hashValue, System::Configuration::Assemblies::AssemblyHashAlgorithm hashAlgorithm);
public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
member this.ExecuteAssembly : string * string[] * byte[] * System.Configuration.Assemblies.AssemblyHashAlgorithm -> int
Public Function ExecuteAssembly (assemblyFile As String, args As String(), hashValue As Byte(), hashAlgorithm As AssemblyHashAlgorithm) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

args
String[]

程序集的入口点的实参。The arguments to the entry point of the assembly.

hashValue
Byte[]

表示计算所得的哈希代码的值。Represents the value of the computed hash code.

hashAlgorithm
AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm AssemblyHashAlgorithm

表示程序集清单使用的哈希算法。Represents the hash algorithm used by the assembly manifest.

返回

程序集的入口点返回的值。The value that is returned by the entry point of the assembly.

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- assemblyFile 使用高于当前所加载版本的公共语言运行时版本编译而成。assemblyFile was compiled with a later version of the common language runtime than the version that is currently loaded.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

此方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

安全性

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence) ExecuteAssembly(String, Evidence)

警告

此 API 现已过时。

使用指定的证据执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified evidence.

public:
 virtual int ExecuteAssembly(System::String ^ assemblyFile, System::Security::Policy::Evidence ^ assemblySecurity);
[System.Obsolete("Use an overload that does not take an Evidence parameter")]
[System.Obsolete("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, System.Security.Policy.Evidence assemblySecurity);
abstract member ExecuteAssembly : string * System.Security.Policy.Evidence -> int
override this.ExecuteAssembly : string * System.Security.Policy.Evidence -> int
Public Function ExecuteAssembly (assemblyFile As String, assemblySecurity As Evidence) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

assemblySecurity
Evidence Evidence Evidence Evidence

用于加载程序集的证据。Evidence for loading the assembly.

返回

程序集的入口点返回的值。The value returned by the entry point of the assembly.

实现

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyFile 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

ExecuteAssembly方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。The ExecuteAssembly method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

安全性

SecurityPermission
若要使用的证据加载程序集。to load an assembly with evidence. 关联枚举: ControlEvidenceAssociated enumeration: ControlEvidence.

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[]) ExecuteAssembly(String, String[])

使用指定的参数执行指定文件中包含的程序集。Executes the assembly contained in the specified file, using the specified arguments.

public:
 int ExecuteAssembly(System::String ^ assemblyFile, cli::array <System::String ^> ^ args);
public int ExecuteAssembly (string assemblyFile, string[] args);
member this.ExecuteAssembly : string * string[] -> int
Public Function ExecuteAssembly (assemblyFile As String, args As String()) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

args
String[]

程序集的入口点的实参。The arguments to the entry point of the assembly.

返回

程序集的入口点返回的值。The value that is returned by the entry point of the assembly.

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- assemblyFile 使用高于当前所加载版本的公共语言运行时版本编译而成。assemblyFile was compiled with a later version of the common language runtime than the version that is currently loaded.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

此方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

安全性

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

ExecuteAssembly(String) ExecuteAssembly(String) ExecuteAssembly(String) ExecuteAssembly(String)

执行指定文件中包含的程序集。Executes the assembly contained in the specified file.

public:
 virtual int ExecuteAssembly(System::String ^ assemblyFile);
public int ExecuteAssembly (string assemblyFile);
abstract member ExecuteAssembly : string -> int
override this.ExecuteAssembly : string -> int
Public Function ExecuteAssembly (assemblyFile As String) As Integer

参数

assemblyFile
String String String String

包含要执行程序集的文件的名称。The name of the file that contains the assembly to execute.

返回

程序集的入口点返回的值。The value returned by the entry point of the assembly.

实现

异常

assemblyFile 未找到。assemblyFile is not found.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

-or- 当前加载的是公共语言运行时 2.0 版或更高版本,而 assemblyFile 是用更高版本编译的。Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

一个程序集或模块用两个不同的证据加载了两次。An assembly or module was loaded twice with two different evidences.

指定的程序集没有入口点。The specified assembly has no entry point.

示例

下面的示例演示了如何使用的重载之一ExecuteAssembly在两个不同的域。The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
   currentDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on [default]"
   otherDomain->ExecuteAssembly( "MyExecutable.exe" );
   
   // Prints S"MyExecutable running on otherDomain"
}

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"
   }
}
Module Test

   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      currentDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on [default]"

      otherDomain.ExecuteAssembly("MyExecutable.exe")
      ' Prints "MyExecutable running on otherDomain"
   End Sub 'Main

End Module 'Test

注解

程序集开始在.NET Framework 标头中指定的入口点执行。The assembly begins executing at the entry point specified in the .NET Framework header.

此方法不会创建新的进程或应用程序域,并且它不在新线程上执行的入口点方法。This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.

此方法加载程序集使用LoadFile方法。This method loads assemblies using the LoadFile method. 此外可以执行使用的程序集ExecuteAssemblyByName方法,加载程序集使用Load方法。You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

若要创建AppDomain若要加载并执行,请使用CreateDomain方法。To create the AppDomain to load and execute, use the CreateDomain method.

安全性

FileIOPermission
用于读取从文件或目录,以及用于访问路径本身中的信息的访问权限。for access to read from a file or directory, and for access to the information in the path itself. 关联枚举: ReadPathDiscoveryAssociated enumerations: Read, PathDiscovery.

WebPermission
用于读取不以"file://"开头的 URI。for reading a URI that does not begin with "file://".

UIPermission
若要执行的控制台应用程序。to execute a console application. 关联枚举: UnrestrictedAssociated enumeration: Unrestricted.

适用于