Defines a persistable dynamic module with the given name that will be saved to the specified file. No symbol information is emitted.
Assembly: mscorlib (in mscorlib.dll)
Public Function DefineDynamicModule ( _ name As String, _ fileName As String _ ) As ModuleBuilder
public ModuleBuilder DefineDynamicModule( string name, string fileName )
public:
ModuleBuilder^ DefineDynamicModule(
String^ name,
String^ fileName
)
member DefineDynamicModule : name:string * fileName:string -> ModuleBuilder
Parameters
- name
- Type: System.String
The name of the dynamic module. Must be less than 260 characters in length.
- fileName
- Type: System.String
The name of the file to which the dynamic module should be saved.
Return Value
Type: System.Reflection.Emit.ModuleBuilderA ModuleBuilder object representing the defined dynamic module.
| Exception | Condition |
|---|---|
| ArgumentNullException |
name or fileName is null. |
| 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 you want the module to contain the assembly manifest, name should be the same as the name of the assembly (that is, the AssemblyName.Name property of the AssemblyName used to create the dynamic assembly) and fileName should be the same as the filename you specify when you save the assembly.
In an assembly with only one module, that module should contain the assembly manifest.
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. |
Note
|
|---|
|
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 persistent dynamic module using DefineDynamicModule.
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 dynamic module that can be saved as the specified DLL name.
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule3", _
"MyModule3.dll")
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 = Thread::GetDomain(); AssemblyName^ myAsmName = gcnew 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" );
.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-
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 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.
Note