AppDomain.ExecuteAssembly Method

Definition

Executes the assembly contained in the specified file.

Overloads

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

Executes the assembly contained in the specified file, using the specified evidence, arguments, hash value, and hash algorithm.

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

Executes the assembly contained in the specified file, using the specified evidence and arguments.

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

Executes the assembly contained in the specified file, using the specified arguments, hash value, and hash algorithm.

ExecuteAssembly(String, Evidence)
Obsolete.

Executes the assembly contained in the specified file, using the specified evidence.

ExecuteAssembly(String, String[])

Executes the assembly contained in the specified file, using the specified arguments.

ExecuteAssembly(String)

Executes the assembly contained in the specified file.

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

Caution

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.

Executes the assembly contained in the specified file, using the specified evidence, arguments, hash value, and hash algorithm.

C#
public int ExecuteAssembly (string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
C#
[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);

Parameters

assemblyFile
String

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

assemblySecurity
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

Represents the hash algorithm used by the assembly manifest.

Returns

The value returned by the entry point of the assembly.

Attributes

Exceptions

assemblyFile is null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

The operation is attempted on an unloaded application domain.

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.

The specified assembly has no entry point.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions (Obsolete)
.NET Framework 1.1, 2.0, 3.0, 3.5 (4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)

ExecuteAssembly(String, Evidence, String[])

Caution

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.

Executes the assembly contained in the specified file, using the specified evidence and arguments.

C#
public int ExecuteAssembly (string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args);
C#
[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);

Parameters

assemblyFile
String

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

assemblySecurity
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

Attributes

Exceptions

assemblyFile is null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

The operation is attempted on an unloaded application domain.

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.

The specified assembly has no entry point.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions (Obsolete)
.NET Framework 1.1, 2.0, 3.0, 3.5 (4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)

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

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

Caution

Code Access Security is not supported or honored by the runtime.

Executes the assembly contained in the specified file, using the specified arguments, hash value, and hash algorithm.

C#
public int ExecuteAssembly (string assemblyFile, string?[]? args, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
C#
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public int ExecuteAssembly (string assemblyFile, string?[]? args, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
C#
public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);

Parameters

assemblyFile
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

Represents the hash algorithm used by the assembly manifest.

Returns

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

Attributes

Exceptions

assemblyFile is null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

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.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

Remarks

Caution

Code Access Security (CAS) has been deprecated across all versions of .NET Framework and .NET. Recent versions of .NET do not honor CAS annotations and produce errors if CAS-related APIs are used. Developers should seek alternative means of accomplishing security tasks.

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.

Applies to

.NET 9 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5 (6, 7, 8, 9)
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ExecuteAssembly(String, Evidence)

Caution

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.

Executes the assembly contained in the specified file, using the specified evidence.

C#
public int ExecuteAssembly (string assemblyFile, System.Security.Policy.Evidence assemblySecurity);
C#
[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);

Parameters

assemblyFile
String

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

assemblySecurity
Evidence

Evidence for loading the assembly.

Returns

The value returned by the entry point of the assembly.

Implements

Attributes

Exceptions

assemblyFile is null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

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.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions (Obsolete)
.NET Framework 1.1, 2.0, 3.0, 3.5 (4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)

ExecuteAssembly(String, String[])

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

Executes the assembly contained in the specified file, using the specified arguments.

C#
public int ExecuteAssembly (string assemblyFile, string?[]? args);
C#
public int ExecuteAssembly (string assemblyFile, string[] args);

Parameters

assemblyFile
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 null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

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.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

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.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ExecuteAssembly(String)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

Executes the assembly contained in the specified file.

C#
public int ExecuteAssembly (string assemblyFile);

Parameters

assemblyFile
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 null.

assemblyFile is not found.

assemblyFile is not a valid assembly for the currently loaded runtime.

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.

Examples

The following sample demonstrates using one of the overloads of ExecuteAssembly on two different domains.

C#
class ExecuteAssemblySnippet {
   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"
   }
}

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.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1