Export (0) Print
Expand All

AssemblyBuilder.DefineDynamicModule Method (String, String, Boolean)

.NET Framework 1.1

Defines a persistable dynamic module, specifying the module name, the name of the file to which the module will be saved, and whether symbol information should be emitted using the default symbol writer.

[Visual Basic]
Overloads Public Function DefineDynamicModule( _
   ByVal name As String, _
   ByVal fileName As String, _
   ByVal emitSymbolInfo As Boolean _
) As ModuleBuilder
[C#]
public ModuleBuilder DefineDynamicModule(
 string name,
 string fileName,
 bool emitSymbolInfo
);
[C++]
public: ModuleBuilder* DefineDynamicModule(
 String* name,
 String* fileName,
 bool emitSymbolInfo
);
[JScript]
public function DefineDynamicModule(
   name : String,
 fileName : String,
 emitSymbolInfo : Boolean
) : 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.
emitSymbolInfo
If true, symbolic information is written using the default symbol writer.

Return Value

A ModuleBuilder object representing the defined dynamic module.

Exceptions

Exception Type Condition
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 the Run attribute.
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.

Remarks

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.

Example

The code example below demonstrates how to create a persistent dynamic module with symbol emission using DefineDynamicModule.

[Visual Basic] 
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. By
' specifying the third parameter as true, we can allow the emission of symbol info.
Dim myModuleBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule4", _
                              "MyModule4.dll", _
                              True)

[C#] 
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. By
// specifying the third parameter as true, we can allow the emission of symbol info.
ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule("MyModule4",
                                 "MyModule4.dll",
                                  true);

[C++] 
AppDomain*  myAppDomain = Thread::GetDomain();
AssemblyName* myAsmName = new AssemblyName();
myAsmName->Name = S"MyAssembly";
AssemblyBuilder*  myAsmBuilder = myAppDomain->DefineDynamicAssembly(myAsmName,
   AssemblyBuilderAccess::Run);
// Create a dynamic module that can be saved as the specified DLL name. By
// specifying the third parameter as true, we can allow the emission of symbol info.
ModuleBuilder*  myModuleBuilder = myAsmBuilder->DefineDynamicModule(S"MyModule4",
   S"MyModule4.dll",
   true);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

AssemblyBuilder Class | AssemblyBuilder Members | System.Reflection.Emit Namespace | AssemblyBuilder.DefineDynamicModule Overload List

Show:
© 2015 Microsoft