Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

AssemblyBuilder.DefineDynamicModule Method (String)

Defines a named transient dynamic module in this assembly.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)
public ModuleBuilder DefineDynamicModule(
	string name
)

Parameters

name
Type: System.String

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

Return Value

Type: System.Reflection.Emit.ModuleBuilder
A ModuleBuilder representing the defined dynamic module.
ExceptionCondition
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 null.

SecurityException

The caller does not have the required permission.

ExecutionEngineException

The assembly for default symbol writer cannot be loaded.

-or-

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

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

The defined dynamic module is transient. 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.

NoteNote:

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. For more information, see .NET Framework 3.5 Architecture.

[Visual Basic, C#]

The code example below demonstrates how to create a transient dynamic module using DefineDynamicModule.

	   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. 
	   ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule1");

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.