AssemblyBuilder.DefineDynamicModule Method (String, String)

Defines a persistable dynamic module with the given name that will be saved to the specified file. No symbol information is emitted.

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

public ModuleBuilder DefineDynamicModule (
	string name,
	string fileName
)
public ModuleBuilder DefineDynamicModule (
	String name, 
	String fileName
)
public function DefineDynamicModule (
	name : String, 
	fileName : String
) : ModuleBuilder

Parameters

name

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

fileName

The name of the file to which the dynamic module should be saved.

Return Value

A ModuleBuilder object representing the defined dynamic module.

Exception typeCondition

ArgumentNullException

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

ArgumentException

The length of name or fileName is zero.

-or-

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

-or-

fileName contains a path specification (a directory component, for example).

-or-

There is a conflict with the name of another file that belongs to this assembly.

InvalidOperationException

This assembly has been previously saved.

NotSupportedException

This assembly was called on a dynamic assembly with Run attribute.

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.

To define a persistable dynamic module, this assembly needs to be created with the Save or the RunAndSave attribute.

If a dynamic assembly contains more than one dynamic module, the assembly's manifest file name should match the module's name that is specified as the first argument to DefineDynamicModule.

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 persistent dynamic module using DefineDynamicModule.

AppDomain myAppDomain = Thread.GetDomain(); 
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "MyAssembly";
AssemblyBuilder myAsmBuilder = myAppDomain.DefineDynamicAssembly(
                     myAsmName,
                     AssemblyBuilderAccess.Run);
// Create a dynamic module that can be saved as the specified DLL name.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule3",
                                 "MyModule3.dll");

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

// Create a dynamic module that can be saved as the specified DLL name.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule(
    "MyModule3", "MyModule3.dll");

  • ReflectionPermission  SecurityAction.Demand, ReflectionEmit=true
  • ReflectionPermission  when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.
  • FileIOPermission  Write=true or Append=true is needed to save the module

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

Community Additions

ADD
Show: