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
)
public ModuleBuilder DefineDynamicModule (
	String name, 
	boolean emitSymbolInfo
)
public function DefineDynamicModule (
	name : String, 
	emitSymbolInfo : boolean
) : ModuleBuilder

Parameters

name

The name of the dynamic module. Must be less than 260 characters in length.

emitSymbolInfo

true if symbol information is to be emitted; otherwise, false.

Return Value

A ModuleBuilder representing the defined dynamic module.

Exception typeCondition

ArgumentException

name begins with white space.

-or-

The length of name is zero.

-or-

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

ArgumentNullException

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

ExecutionEngineException

The assembly for default symbol writer cannot be loaded.

-or-

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

SecurityException

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.

NoteNote

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.

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(
                     myAsmName,
                     AssemblyBuilderAccess.Run);

// 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",
                                 false);

AppDomain myAppDomain = System.Threading.Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.set_Name("MyAssembly");
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
    myAsmName, AssemblyBuilderAccess.Run);

// 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", false);

  • ReflectionPermission  SecurityAction.Demand, ReflectionEmit=true
  • ReflectionPermission  when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: