Export (0) Print
Expand All

AppDomain.ExecuteAssembly Method (String)

Executes the assembly contained in the specified file.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public int ExecuteAssembly (
	string assemblyFile
)
public final int ExecuteAssembly (
	String assemblyFile
)
public final function ExecuteAssembly (
	assemblyFile : String
) : int
Not applicable.

Parameters

assemblyFile

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

Return Value

The value returned by the entry point of the assembly.

Exception typeCondition

ArgumentNullException

assemblyFile is a null reference (Nothing in Visual Basic).

FileNotFoundException

assemblyFile is not found.

BadImageFormatException

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.

AppDomainUnloadedException

The operation is attempted on an unloaded application domain.

FileLoadException

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

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.

Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: Loading assemblies into a domain neutral code area for use by multiple application domains is not supported.

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

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft