This documentation is archived and is not being maintained.

AssemblyBuilder.DefineDynamicModule Method (String, Boolean)

Defines a named transient dynamic module in this assembly and specifies whether symbol information should be emitted.

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

public ModuleBuilder DefineDynamicModule(
	string name,
	bool emitSymbolInfo


Type: System.String
The name of the dynamic module. Must be less than 260 characters in length.
Type: System.Boolean
true if symbol information is to be emitted; otherwise, false.

Return Value

Type: System.Reflection.Emit.ModuleBuilder
A ModuleBuilder representing the defined dynamic module.


name begins with white space.


The length of name is zero.


The length of name is greater than or equal to 260.


name is null.


The assembly for default symbol writer cannot be loaded.


The type that implements the default symbol writer interface cannot be found.


The caller does not have the required permission.

It is an error to define multiple dynamic modules with the same name in an assembly.

The dynamic module is not saved, even if the parent dynamic assembly was created with RunAndSave.


To suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute to the dynamic assembly before calling DefineDynamicModule. Create an instance of DebuggableAttribute with the DisableOptimizations flag and apply it using the SetCustomAttribute method. The attribute must be applied to the dynamic assembly. It has no effect if applied to the module.


Starting with the .NET Framework version 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework version 3.5 or later.

[Visual Basic, C#]

The code example below demonstrates how to create a transient dynamic module using DefineDynamicModule, suppressing symbol information.

	   AppDomain myAppDomain = Thread.GetDomain(); 
	   AssemblyName myAsmName = new AssemblyName();
	   myAsmName.Name = "MyAssembly";
	   AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(

	   // Create a transient dynamic module. Since no DLL name is specified with
	   // this constructor, it can not be saved. By specifying the second parameter
	   // of the constructor as false, we can suppress the emission of symbol info.
	   ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule2",

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.