AppDomain.DefineDynamicAssembly Method (AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>)

.NET Framework (current version)

Defines a dynamic assembly using the specified name, access mode, storage directory, and synchronization option.

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

public AssemblyBuilder DefineDynamicAssembly(
	AssemblyName name,
	AssemblyBuilderAccess access,
	string dir,
	bool isSynchronized,
	IEnumerable<CustomAttributeBuilder> assemblyAttributes


Type: System.Reflection.AssemblyName

The unique identity of the dynamic assembly.

Type: System.Reflection.Emit.AssemblyBuilderAccess

The mode in which the dynamic assembly will be accessed.

Type: System.String

The name of the directory where the dynamic assembly will be saved. If dir is null, the current directory is used.

Type: System.Boolean

true to synchronize the creation of modules, types, and members in the dynamic assembly; otherwise, false.

Type: System.Collections.Generic.IEnumerable<CustomAttributeBuilder>

An enumerable list of attributes to be applied to the assembly, or null if there are no attributes.

Return Value

Type: System.Reflection.Emit.AssemblyBuilder

A dynamic assembly with the specified name and features.

Exception Condition

name is null.


The Name property of name is null.


The Name property of name starts with white space, or contains a forward or backward slash.


The operation is attempted on an unloaded application domain.

Use this method overload to specify attributes that do not work correctly unless they are applied when a dynamic assembly is created. For example, security attributes such as SecurityTransparentAttribute and SecurityCriticalAttribute do not work correctly if they are added after a dynamic assembly has been created.

If isSynchronized is true, the following methods of the resulting AssemblyBuilder will be synchronized: DefineDynamicModule, DefineResource, AddResourceFile, GetDynamicModule, SetEntryPoint, and Save. If two of these methods are called on different threads, one will block until the other is completed.

.NET Framework
Available since 4.0
Return to top