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

Definition

Executes the assembly contained in the specified file.

Overloads

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)

Warning

This API is now obsolete.

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

Parameters

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.

Returns

The value returned by the entry point of the assembly.

Exceptions

assemblyFile is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

An assembly or module was loaded twice with two different evidences.

assemblySecurity is not null. When legacy CAS policy is not enabled, assemblySecurity should be null.

Examples

Thefollowing 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

Remarks

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

Security

SecurityPermission
to load an assembly with evidence. Associated enumeration: ControlEvidence.

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated enumeration: Unrestricted.

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

Warning

This API is now obsolete.

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

Parameters

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.

Returns

The value returned by the entry point of the assembly.

Implements

Exceptions

assemblyFile is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

An assembly or module was loaded twice with two different evidences.

assemblySecurity is not null. When legacy CAS policy is not enabled, assemblySecurity should be null.

Examples

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

Remarks

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

Security

SecurityPermission
to load an assembly with evidence. Associated enumeration: ControlEvidence.

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated 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

Parameters

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.

Returns

The value that is returned by the entry point of the assembly.

Exceptions

assemblyFile is not a valid assembly.

-or-

assemblyFile was compiled with a later version of the common language runtime than the version that is currently loaded.

An assembly or module was loaded twice with two different evidences.

Examples

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

Remarks

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

Security

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated enumeration: Unrestricted.

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

Warning

This API is now obsolete.

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

Parameters

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.

Returns

The value returned by the entry point of the assembly.

Implements

Exceptions

assemblyFile is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

An assembly or module was loaded twice with two different evidences.

Examples

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

Remarks

The assembly begins executing at the entry point specified in the .NET Framework header.

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

Security

SecurityPermission
to load an assembly with evidence. Associated enumeration: ControlEvidence.

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated 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

Parameters

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.

Returns

The value that is returned by the entry point of the assembly.

Exceptions

assemblyFile is not a valid assembly.

-or-

assemblyFile was compiled with a later version of the common language runtime than the version that is currently loaded.

An assembly or module was loaded twice with two different evidences.

Examples

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

Remarks

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

Security

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated 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

Parameters

assemblyFile
String String String String

The name of the file that contains the assembly to execute.

Returns

The value returned by the entry point of the assembly.

Implements

Exceptions

assemblyFile is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyFile was compiled with a later version.

An assembly or module was loaded twice with two different evidences.

Examples

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

Remarks

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.

This method loads assemblies using the LoadFile method. You can also execute assemblies using the ExecuteAssemblyByName method, which loads assemblies using the Load method.

To create the AppDomain to load and execute, use the CreateDomain method.

Security

FileIOPermission
for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: Read, PathDiscovery.

WebPermission
for reading a URI that does not begin with "file://".

UIPermission
to execute a console application. Associated enumeration: Unrestricted.

Applies to