AppDomain.ExecuteAssembly Method (String, Evidence, String[]) (System)

Switch View :
ScriptFree
.NET Framework Class Library
AppDomain.ExecuteAssembly Method (String, Evidence, String[])

Updated: May 2010

Note: This API is now obsolete. The non-obsolete alternative is ExecuteAssembly(String, String[]).

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

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

Visual Basic
<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 Function ExecuteAssembly ( _
	assemblyFile As String, _
	assemblySecurity As Evidence, _
	args As String() _
) As Integer
C#
[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
)
Visual C++
[ObsoleteAttribute(L"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:
virtual int ExecuteAssembly(
	String^ assemblyFile, 
	Evidence^ assemblySecurity, 
	array<String^>^ args
) sealed
F#
[<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.")>]
abstract ExecuteAssembly : 
        assemblyFile:string * 
        assemblySecurity:Evidence * 
        args:string[] -> int 
[<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.")>]
override ExecuteAssembly : 
        assemblyFile:string * 
        assemblySecurity:Evidence * 
        args:string[] -> int 

Parameters

assemblyFile
Type: System.String
The name of the file that contains the assembly to execute.
assemblySecurity
Type: System.Security.Policy.Evidence
The supplied evidence for the assembly.
args
Type: System.String[]
The arguments to the entry point of the assembly.

Return Value

Type: System.Int32
The value returned by the entry point of the assembly.

Implements

_AppDomain.ExecuteAssembly(String, Evidence, String[])
Exceptions

Exception Condition
ArgumentNullException

assemblyFile is null.

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.

NotSupportedException

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

MissingMethodException

The specified assembly has no entry point.

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.

Examples

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

Visual Basic

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


C#

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


Visual C++

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



Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Obsolete (compiler warning) in 4

.NET Framework Client Profile

Supported in: 3.5 SP1
Obsolete (compiler warning) in 4
.NET Framework Security

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Change History

Date

History

Reason

May 2010

Added missing MissingMethodException exception and UIPermission permission.

Customer feedback.