Edit

AssemblyBuilder.DefineDynamicModule(String) Method

Definition

Defines a named transient dynamic module in this assembly.

public:
 System::Reflection::Emit::ModuleBuilder ^ DefineDynamicModule(System::String ^ name);
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule(string name);
member this.DefineDynamicModule : string -> System.Reflection.Emit.ModuleBuilder
Public Function DefineDynamicModule (name As String) As ModuleBuilder

Parameters

name
String

The name of the dynamic module.

Returns

A ModuleBuilder representing the defined dynamic module.

Exceptions

name begins with white space.

-or-

The length of name is zero.

-or-

The length of name is greater than the system-defined maximum length.

-or-

.NET Framework only: A module with the same name has already been defined in this assembly.

name is null.

.NET Core and .NET 5+ only: A dynamic module has already been defined in this assembly.

The caller does not have the required permission.

The assembly for default symbol writer cannot be loaded.

-or-

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

Examples

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");
Dim myAppDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "MyAssembly"
Dim myAsmBuilder As AssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAsmName, _
                      AssemblyBuilderAccess.Run)

' Create a transient dynamic module. Since no DLL name is specified with
' this constructor, it can not be saved. 
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule1")

Remarks

.NET Core and .NET 5+ only: Multi-module assemblies are not supported. Only one dynamic module may be defined in an assembly.

.NET Framework only: 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.

Note

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.

Applies to