[CLSCompliant(false)] |
Multiple application domains can run in a single process; however, there is not a one-to-one correlation between application domains and threads. Several threads can belong to a single application domain, and while a given thread is not confined to a single application domain, at any given time, a thread executes in a single application domain.
Application domains are created using the AppDomain.CreateDomain method. AppDomain instances are used to load and execute assemblies ( Assembly). When a AppDomain is no longer in use, it can be unloaded.
The _AppDomain interface implements a set of events to enable applications to respond when an assembly is loaded, an application domain will be unloaded, or an unhandled exception is thrown.
BaseDirectory | Read-only Gets the base directory that the assembly resolver used to probe for assemblies. |
DynamicDirectory | Read-only Gets the directory that the assembly resolver used to probe for dynamically-created assemblies. |
Evidence | Read-only Gets the Evidence associated with this application domain that is used as input to security policy. |
FriendlyName | Read-only Gets the friendly name of this application domain. |
RelativeSearchPath | Read-only Gets the path relative to the base directory where the assembly resolver should probe for private assemblies. |
ShadowCopyFiles | Read-only Gets an indication whether all assemblies loaded in the application domain are shadow copied. |
AppendPrivatePath | Appends the specified name of the directory to the private path. |
ClearPrivatePath | Resets the path that specifies the location of private assemblies to the empty string (""). |
ClearShadowCopyPath | Resets the list of directories containing shadow copied assemblies to the empty string (""). |
CreateInstance | Overloaded:CreateInstance(string assemblyName, string typeName) Creates a new instance of the specified type defined in the specified assembly. |
CreateInstance | Overloaded:CreateInstance(string assemblyName, string typeName, object[] activationAttributes) Creates a new instance of the specified type defined in the specified assembly. A parameter specifies an array of activation attributes. |
CreateInstance | Overloaded:CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes) Creates a new instance of the specified type defined in the specified assembly. Parameters specify a binder, binding flags, constructor arguments, culture-specific information used to interpret arguments, activation attributes, and authorization to create the type. |
CreateInstanceFrom | Overloaded:CreateInstanceFrom(string assemblyFile, string typeName) Creates a new instance of the specified type defined in the specified assembly file. |
CreateInstanceFrom | Overloaded:CreateInstanceFrom(string assemblyFile, string typeName, object[] activationAttributes) Creates a new instance of the specified type defined in the specified assembly file. |
CreateInstanceFrom | Overloaded:CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes) Creates a new instance of the specified type defined in the specified assembly file. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) Defines a dynamic assembly with the specified name and access mode. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence) Defines a dynamic assembly using the specified name, access mode, and evidence. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir) Defines a dynamic assembly using the specified name, access mode, and storage directory. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence) Defines a dynamic assembly using the specified name, access mode, storage directory, and evidence. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) Defines a dynamic assembly using the specified name, access mode, and permission requests. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) Defines a dynamic assembly using the specified name, access mode, evidence, and permission requests. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) Defines a dynamic assembly using the specified name, access mode, storage directory, and permission requests. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) Defines a dynamic assembly using the specified name, access mode, storage directory, evidence, and permission requests. |
DefineDynamicAssembly | Overloaded:DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized) Defines a dynamic assembly using the specified name, access mode, storage directory, evidence, permission requests, and synchronization option. |
DoCallBack | Executes the code in another application domain that is identified by the specified delegate. |
Equals | Returns a value indicating whether this instance is equal to a specified object. |
ExecuteAssembly | Overloaded:ExecuteAssembly(string assemblyFile) Execute the Assembly given its file name. The method specified in the .NET Framework header is called. |
ExecuteAssembly | Overloaded:ExecuteAssembly(string assemblyFile, Evidence assemblySecurity) Execute the Assembly given its file name and supplied evidence. |
ExecuteAssembly | Overloaded:ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args) Execute the Assembly given its file name and supplied Evidence. Optionally, the Assembly can be loaded into the domain-neutral code area for use by multiple AppDomains. |
GetAssemblies | Gets the assemblies that have been loaded into this application domain. |
GetData | Gets the value stored in the current application domain for the specified data name. |
GetHashCode | Returns the hash code for this instance. |
GetLifetimeService | Returns a lifetime service object that controls the lifetime policy for an instance that implements this interface. |
GetType | Gets the type of the current instance. |
InitializeLifetimeService | Gives the AppDomain an infinite lifetime by preventing a lease from being created. |
Load | Overloaded:Load(AssemblyName assemblyRef) Loads an Assembly given its AssemblyName. |
Load | Overloaded:Load(byte[] rawAssembly) Loads the Assembly with a COFF based image containing an emitted Assembly. |
Load | Overloaded:Load(string assemblyString) Loads an Assembly given its display name. |
Load | Overloaded:Load(AssemblyName assemblyRef, Evidence assemblySecurity) Loads an Assembly given its AssemblyName. |
Load | Overloaded:Load(byte[] rawAssembly, byte[] rawSymbolStore) Loads the Assembly with a COFF based image containing an emitted Assembly. The raw bytes representing the symbols for the Assembly are also loaded. |
Load | Overloaded:Load(string assemblyString, Evidence assemblySecurity) Loads an Assembly given its display name. |
Load | Overloaded:Load(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence) Loads the Assembly with a COFF based image containing an emitted Assembly. The raw bytes representing the symbols for the Assembly are also loaded. |
SetAppDomainPolicy | Establishes the security policy level for this application domain. |
SetCachePath | Establishes the specified directory path as the location where assemblies are shadow copied. |
SetData | Assigns the specified value to the specified application domain property. |
SetPrincipalPolicy | Specifies how principal and identity objects should be attached to a thread if the thread attempts to bind to a principal while executing in this application domain. |
SetShadowCopyPath | Establishes the specified directory path as the location of assemblies to be shadow copied. |
SetThreadPrincipal | Set the default principal object to be attached to threads if they attempt to bind to a principal while executing in this application domain. |
ToString | Obtains the String representation of this instance. |
AssemblyLoad | Occurs when an assembly is loaded. |
AssemblyResolve | Occurs when the resolution of an assembly fails. |
DomainUnload | Occurs when an AppDomain is about to be unloaded. |
ProcessExit | Occurs when a process is about to exit. |
ResourceResolve | Occurs when the resolution of a resource fails. |
TypeResolve | Occurs when the resolution of a type fails. |
UnhandledException | Occurs when an exception is not caught by an event handler. |
string BaseDirectory {get;}
|
string DynamicDirectory {get;}
|
Evidence Evidence {get;}
|
string FriendlyName {get;}
|
"c:\MyAppDirectory\MyAssembly.exe"
is loaded in the default application domain, the friendly name of that application domain is
"MyAssembly.exe"
.
string RelativeSearchPath {get;}
|
bool ShadowCopyFiles {get;}
|
void AppendPrivatePath( |
path
void ClearPrivatePath(); |
For more information, see AppDomainSetup.PrivateBinPath.
void ClearShadowCopyPath(); |
For more information, see AppDomainSetup.ShadowCopyDirectories.
ObjectHandle CreateInstance( |
assemblyName
typeName
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyName or typeName is null. |
See AssemblyName for the format of assemblyName.
ObjectHandle CreateInstance( |
assemblyName
typeName
activationAttributes
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyName or typeName is null. |
See AssemblyName for the format of assemblyName.
ObjectHandle CreateInstance( |
assemblyName
typeName
ignoreCase
bindingAttr
binder
args
culture
activationAttributes
securityAttributes
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyName or typeName is null. |
See AssemblyName for the format of assemblyName.
ObjectHandle CreateInstanceFrom( |
assemblyFile
typeName
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. -or- typeName is null. |
For more information, see the Activator.CreateInstanceFrom method.
ObjectHandle CreateInstanceFrom( |
assemblyFile
typeName
activationAttributes
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. -or- typeName is null. |
For more information, see the Activator.CreateInstanceFrom method.
ObjectHandle CreateInstanceFrom( |
assemblyFile
typeName
ignoreCase
bindingAttr
binder
args
culture
activationAttributes
securityAttributes
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. -or- typeName is null. |
AssemblyBuilder DefineDynamicAssembly( |
name
access
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
evidence
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.
This method should only be used to define a dynamic assembly in the current application domain. For more information, see the Remarks section of the topic.
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
dir
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
dir
evidence
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.
This method should only be used to define a dynamic assembly in the current application domain. For more information, see the Remarks section of the topic.
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
requiredPermissions
optionalPermissions
refusedPermissions
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
evidence
requiredPermissions
optionalPermissions
refusedPermissions
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.
This method should only be used to define a dynamic assembly in the current application domain. For more information, see the Remarks section of the topic.
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
dir
requiredPermissions
optionalPermissions
refusedPermissions
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
dir
evidence
requiredPermissions
optionalPermissions
refusedPermissions
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.
This method should only be used to define a dynamic assembly in the current application domain. For more information, see the Remarks section of the topic.
The name parameter indirectly specifies a Version (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. For example, if the Assembly.LoadFrom method is used to indirectly recover the Version for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
AssemblyBuilder DefineDynamicAssembly( |
name
access
dir
evidence
requiredPermissions
optionalPermissions
refusedPermissions
isSynchronized
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
ArgumentException | The Name property of name is null. -or- The Name property of name begins with white space, or contains a forward or backward slash. |
If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.
The name parameter indirectly specifies a Version object (as an OperatingSystem.#ctor constructor parameter). However, this method only persists the major and minor version numbers, not the build and revision numbers. That is, for example, if the Assembly.LoadFrom method is used to indirectly recover the Version object for this assembly, only that object's major and minor version numbers will be as originally specified.
using System; using System.Reflection; using System.Reflection.Emit; class Test { public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; InstantiateMyDynamicType(currentDomain); // Failed! currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); InstantiateMyDynamicType(currentDomain); // OK! } static void InstantiateMyDynamicType(AppDomain domain) { try { domain.CreateInstance("MyDynamicAssembly", "MyDynamicType"); } catch (Exception e) { Console.WriteLine(e.Message); } } static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefineDynamicAssembly((AppDomain) sender); } static Assembly DefineDynamicAssembly(AppDomain domain) { // Build a dynamic assembly using Reflection Emit API. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyDynamicAssembly"; AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyDynamicModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("MyDynamicType instantiated!"); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); return assemblyBuilder; } }
void DoCallBack( |
theDelegate
other
assemblyFile
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. |
FileNotFoundException | assemblyFile is not found. |
BadImageFormatException | assemblyFile is not a valid assembly. |
assemblyFile
assemblySecurity
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. |
FileNotFoundException | assemblyFile is not found. |
BadImageFormatException | assemblyFile is not a valid assembly. |
assemblyFile
assemblySecurity
args
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyFile is null. |
FileNotFoundException | assemblyFile is not found. |
BadImageFormatException | assemblyFile is not a valid assembly. |
Assembly[] GetAssemblies(); |
name
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
int GetHashCode(); |
object GetLifetimeService(); |
Type GetType(); |
object InitializeLifetimeService(); |
Assembly Load( |
assemblyRef
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyRef is null |
FileNotFoundException | assemblyRef is not found. |
BadImageFormatException | assemblyRef is not a valid assembly. |
An attempt to call AppDomain.Load on an application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since Assembly objects are not MarshalByRef, when the method attempts to return the Assembly object for the loaded assembly to the current application domain, the runtime will try to load the specified assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
rawAssembly
Exception Type | Condition |
---|---|
ArgumentNullException | rawAssembly is null. |
BadImageFormatException | rawAssembly is not a valid assembly. |
An attempt to call AppDomain.Load on an application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since Assembly objects are not MarshalByRef, when the method attempts to return the Assembly object for the loaded assembly to the current application domain, the runtime will try to load the specified assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
assemblyString
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyString is null |
FileNotFoundException | assemblyString is not found. |
BadImageFormatException | assemblyString is not a valid assembly. |
An attempt to call AppDomain.Load on an application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since Assembly objects are not MarshalByRef, when the method attempts to return the Assembly object for the loaded assembly to the current application domain, the runtime will try to load the specified assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
Assembly Load( |
assemblyRef
assemblySecurity
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyRef is null |
FileNotFoundException | assemblyRef is not found. |
BadImageFormatException | assemblyRef is not a valid assembly. |
rawAssembly
rawSymbolStore
Exception Type | Condition |
---|---|
ArgumentNullException | rawAssembly is null. |
BadImageFormatException | rawAssembly is not a valid assembly. |
An attempt to call AppDomain.Load on an application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since Assembly objects are not MarshalByRef, when the method attempts to return the Assembly object for the loaded assembly to the current application domain, the runtime will try to load the specified assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
assemblyString
assemblySecurity
Exception Type | Condition |
---|---|
ArgumentNullException | assemblyString is null |
FileNotFoundException | assemblyString is not found. |
BadImageFormatException | assemblyString is not a valid assembly. |
rawAssembly
rawSymbolStore
securityEvidence
Exception Type | Condition |
---|---|
ArgumentNullException | rawAssembly is null. |
BadImageFormatException | rawAssembly is not a valid assembly. |
An attempt to call AppDomain.Load on an application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since Assembly objects are not MarshalByRef, when the method attempts to return the Assembly object for the loaded assembly to the current application domain, the runtime will try to load the specified assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
void SetAppDomainPolicy( |
domainPolicy
Exception Type | Condition |
---|---|
ArgumentNullException | domainPolicy is null. |
PolicyException | The security policy level has already been set. |
void SetCachePath( |
s
name
data
Value of 'name' | Property |
---|---|
"APPBASE" | ApplicationBase |
"APP_CONFIG_FILE" | ConfigurationFile |
"DYNAMIC_BASE" | DynamicBase |
"DEV_PATH" | (no property) |
"APP_NAME" | ApplicationName |
"CACHE_BASE" | PrivateBinPath |
"BINPATH_PROBE_ONLY" | PrivateBinPathProbe |
"SHADOW_COPY_DIRS" | ShadowCopyDirectories |
"FORCE_CACHE_INSTALL" | ShadowCopyFiles |
"CACHE_BASE" | CachePath |
(application specific) | LicenseFile |
void SetPrincipalPolicy( |
policy
void SetShadowCopyPath( |
s
void SetThreadPrincipal( |
principal
Exception Type | Condition |
---|---|
ArgumentNullException | principal is null. |
PolicyException | The thread principal has already been set. |
string ToString(); |
event AssemblyLoadEventHandler AssemblyLoad;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event ResolveEventHandler AssemblyResolve;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event EventHandler DomainUnload;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event EventHandler ProcessExit;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event ResolveEventHandler ResourceResolve;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event ResolveEventHandler TypeResolve;
|
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.
event UnhandledExceptionEventHandler UnhandledException;
|
This event occurs only for the application domain that is created by the system when an application is started. If an application creates additional application domains, specifying a delegate for this event in those applications domains has no effect.
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.