System.Reflection.Emit.AssemblyBuilder Class

Assembly: Mscorlib.dll
Namespace: System.Reflection.Emit
Summary
Defines and represents a dynamic assembly.
C# Syntax:
public sealed class AssemblyBuilder : Assembly
Thread Safety
Reflection Emit is thread-safe when using assemblies that were created with the AppDomain.DefineDynamicAssembly method with the Boolean parameter isSynchronized set to true.
Remarks
A dynamic assembly is an assembly that is created using the Reflection Emit APIs. The dynamic modules in the assembly are saved when the dynamic assembly is saved using the AssemblyBuilder.Save method. To generate an executable, the AssemblyBuilder.SetEntryPoint method must be called to identify the method that is the entry point to the assembly. Assemblies are saved as DLL by default, unless AssemblyBuilder.SetEntryPoint requests the generation of a console application or a Windows-based application.

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 AssemblyBuilder.DefineDynamicModule.

Some methods on the base class Assembly such as GetModules and GetLoadedModules will not work correctly when called AssemblyBuilder objects. You can load the defined dynamic assembly and call the methods on the loaded assembly. For example, to ensure that resource modules are included in the returned module list, call GetModules on the loaded Assembly object.

The signing of a dynamic assembly using AssemblyName.KeyPair is not effective until the assembly is saved to disk. So, strong names will not work with transient dynamic assemblies.
See also:
System.Reflection.Emit Namespace

System.Reflection.Emit.AssemblyBuilder Member List:

Public Properties
CodeBase Read-only

Overridden:
Gets the location of the assembly, as specified originally (such as in an AssemblyName object).
EntryPoint Read-only

Overridden:
Returns the entry point of this assembly.
EscapedCodeBase
(inherited from System.Reflection.Assembly)
Read-only

See base class member description: System.Reflection.Assembly.EscapedCodeBase


Gets the URI, including escape characters, that represents the codebase.
Evidence
(inherited from System.Reflection.Assembly)
Read-only

See base class member description: System.Reflection.Assembly.Evidence


Gets the evidence for this assembly.
FullName
(inherited from System.Reflection.Assembly)
Read-only

See base class member description: System.Reflection.Assembly.FullName


Gets the display name of the assembly.
GlobalAssemblyCache
(inherited from System.Reflection.Assembly)
Read-only

See base class member description: System.Reflection.Assembly.GlobalAssemblyCache


Gets a value indicating whether the assembly was loaded from the global assembly cache.
Location Read-only

Overridden:
Gets the location, in codebase format, of the loaded file that contains the manifest if it is not shadow-copied.
Public Methods
AddResourceFile Overloaded:
AddResourceFile(string name, string fileName)

Adds an existing resource file to this assembly.
AddResourceFile Overloaded:
AddResourceFile(string name, string fileName, ResourceAttributes attribute)

Adds an existing resource file to this assembly.
CreateInstance
(inherited from System.Reflection.Assembly)
Overloaded:
CreateInstance(string typeName)

See base class member description: System.Reflection.Assembly.CreateInstance


Locates the specified type from this assembly and creates an instance of it using the system activator, using case-sensitive search.
CreateInstance
(inherited from System.Reflection.Assembly)
Overloaded:
CreateInstance(string typeName, bool ignoreCase)

See base class member description: System.Reflection.Assembly.CreateInstance


Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search.
CreateInstance
(inherited from System.Reflection.Assembly)
Overloaded:
CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)

See base class member description: System.Reflection.Assembly.CreateInstance


Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search and having the specified culture, arguments, and binding and activation attributes.
DefineDynamicModule Overloaded:
DefineDynamicModule(string name)

Defines a named transient dynamic module in this assembly.
DefineDynamicModule Overloaded:
DefineDynamicModule(string name, bool emitSymbolInfo)

Defines a named transient dynamic module in this assembly and specifies whether symbol information should be emitted.
DefineDynamicModule Overloaded:
DefineDynamicModule(string name, string fileName)

Defines a dynamic module with the given name that will be saved to the specified file. No symbol information is emitted.
DefineDynamicModule Overloaded:
DefineDynamicModule(string name, string fileName, bool emitSymbolInfo)

Defines a persistable dynamic module in this dynamic assembly that includes symbolic information using the default symbol writer.
DefineResource Overloaded:
DefineResource(string name, string description, string fileName)

Defines a standalone managed resource for this assembly with the default public resource attribute.
DefineResource Overloaded:
DefineResource(string name, string description, string fileName, ResourceAttributes attribute)

Defines a standalone managed resource for this assembly. Attributes can be specified for the managed resource.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetCustomAttributes
(inherited from System.Reflection.Assembly)
Overloaded:
GetCustomAttributes(bool inherit)

See base class member description: System.Reflection.Assembly.GetCustomAttributes


Gets all the custom attributes for this assembly.
GetCustomAttributes
(inherited from System.Reflection.Assembly)
Overloaded:
GetCustomAttributes(Type attributeType, bool inherit)

See base class member description: System.Reflection.Assembly.GetCustomAttributes


Gets the custom attributes for this assembly as specified by type.
GetDynamicModule Returns the dynamic module with the specified name.
GetExportedTypes Overridden:
Gets the exported types defined in this assembly.
GetFile Overridden:
Gets a FileStream for the specified file in the file table of the manifest of this assembly.
GetFiles
(inherited from System.Reflection.Assembly)
Overloaded:
GetFiles()

See base class member description: System.Reflection.Assembly.GetFiles


Gets the files in the file table of an assembly manifest.
GetFiles Overloaded:
GetFiles(bool getResourceModules)

Overridden:
Gets the files in the file table of an assembly manifest, specifying whether to include resource modules.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLoadedModules
(inherited from System.Reflection.Assembly)
Overloaded:
GetLoadedModules()

See base class member description: System.Reflection.Assembly.GetLoadedModules


Gets all the loaded modules that are part of this assembly.
GetLoadedModules
(inherited from System.Reflection.Assembly)
Overloaded:
GetLoadedModules(bool getResourceModules)

See base class member description: System.Reflection.Assembly.GetLoadedModules


Gets all the loaded modules that are part of this assembly, specifying whether to include resource modules.
GetManifestResourceInfo Overridden:
Returns information about how the given resource has been persisted.
GetManifestResourceNames Overridden:
Loads the specified manifest resource from this assembly.
GetManifestResourceStream Overloaded:
GetManifestResourceStream(string name)

Overridden:
Loads the specified manifest resource from this assembly.
GetManifestResourceStream Overloaded:
GetManifestResourceStream(Type type, string name)

Overridden:
Loads the specified manifest resource, scoped by the namespace of the specified type, from this assembly.
GetModule
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.GetModule


Gets the specified module in this assembly.
GetModules
(inherited from System.Reflection.Assembly)
Overloaded:
GetModules()

See base class member description: System.Reflection.Assembly.GetModules


Gets all the modules that are part of this assembly.
GetModules
(inherited from System.Reflection.Assembly)
Overloaded:
GetModules(bool getResourceModules)

See base class member description: System.Reflection.Assembly.GetModules


Gets all the modules that are part of this assembly, specifying whether to include resource modules.
GetName
(inherited from System.Reflection.Assembly)
Overloaded:
GetName()

See base class member description: System.Reflection.Assembly.GetName


Gets an AssemblyName for this assembly.
GetName
(inherited from System.Reflection.Assembly)
Overloaded:
GetName(bool copiedName)

See base class member description: System.Reflection.Assembly.GetName


Gets an AssemblyName for this assembly, setting the codebase as specified by copiedName.
GetObjectData
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.GetObjectData


Gets serialization information with all of the data needed to reinstantiate this assembly.
GetReferencedAssemblies
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.GetReferencedAssemblies


Gets the AssemblyName objects for all the assemblies referenced by this assembly.
GetSatelliteAssembly
(inherited from System.Reflection.Assembly)
Overloaded:
GetSatelliteAssembly(CultureInfo culture)

See base class member description: System.Reflection.Assembly.GetSatelliteAssembly


Gets the satellite assembly for the specified culture.
GetSatelliteAssembly
(inherited from System.Reflection.Assembly)
Overloaded:
GetSatelliteAssembly(CultureInfo culture, Version version)

See base class member description: System.Reflection.Assembly.GetSatelliteAssembly


Gets the specified version of the satellite assembly for the specified culture.
GetType
(inherited from System.Object)
Overloaded:
GetType()

See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Reflection.Assembly)
Overloaded:
GetType(string name)

See base class member description: System.Reflection.Assembly.GetType


Gets the Type object with the specified name in the assembly instance.
GetType
(inherited from System.Reflection.Assembly)
Overloaded:
GetType(string name, bool throwOnError)

See base class member description: System.Reflection.Assembly.GetType


Gets the Type object with the specified name in the assembly instance and optionally throws an exception.
GetType
(inherited from System.Reflection.Assembly)
Overloaded:
GetType(string name, bool throwOnError, bool ignoreCase)

See base class member description: System.Reflection.Assembly.GetType


Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and throwing an exception.
GetTypes
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.GetTypes


Gets the types defined in this assembly.
IsDefined
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.IsDefined


Indicates whether a custom attribute identified by the specified Type is defined.
LoadModule
(inherited from System.Reflection.Assembly)
Overloaded:
LoadModule(string moduleName, byte[] rawModule)

See base class member description: System.Reflection.Assembly.LoadModule


Loads the module, internal to this assembly, with a Common Object File Format (COFF)-based image containing an emitted module, or a resource file.
LoadModule
(inherited from System.Reflection.Assembly)
Overloaded:
LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)

See base class member description: System.Reflection.Assembly.LoadModule


Loads the module, internal to this assembly, with a Common Object File Format (COFF)-based image containing an emitted module, or a resource file. The raw bytes representing the symbols for the module are also loaded.
Save Saves this dynamic assembly to disk.
SetCustomAttribute Overloaded:
SetCustomAttribute(CustomAttributeBuilder customBuilder)

Set a custom attribute on this assembly using a custom attribute builder.
SetCustomAttribute Overloaded:
SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)

Set a custom attribute on this assembly using a specified custom attribute blob.
SetEntryPoint Overloaded:
SetEntryPoint(MethodInfo entryMethod)

Sets the entry point for this dynamic assembly, assuming that a console application is being built.
SetEntryPoint Overloaded:
SetEntryPoint(MethodInfo entryMethod, PEFileKinds fileKind)

Sets the entry point for this assembly and defines the type of the PE being built.
ToString
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.ToString


Returns the full name of the assembly, also known as the display name.
Public Events
ModuleResolve
(inherited from System.Reflection.Assembly)
See base class member description: System.Reflection.Assembly.ModuleResolve


Occurs when the common language runtime class loader cannot resolve a reference to an internal module of an assembly through normal means.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Reflection.Emit.AssemblyBuilder Member Details

Overridden Property: CodeBase (read-only)
Summary
Gets the location of the assembly, as specified originally (such as in an AssemblyName object).
C# Syntax:
public override string CodeBase {get;}
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.
Remarks
To get the absolute path to the loaded manifest-containing file, use the Assembly.Location property.
Example
This example shows an expression that uses the CodeBase property.
    StringBuilder codebase = new StringBuilder(Assembly.Load("mscorlib").CodeBase);

    

Return to top


Overridden Property: EntryPoint (read-only)
Summary
Returns the entry point of this assembly.
C# Syntax:
public override MethodInfo EntryPoint {get;}

Return to top


Property: EscapedCodeBase (read-only)
Inherited
See base class member description: System.Reflection.Assembly.EscapedCodeBase

Summary
Gets the URI, including escape characters, that represents the codebase.
C# Syntax:
public virtual string EscapedCodeBase {get;}
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
.NET Framework Security:
FileIOPermission for access to the path. Associated enumeration: FileIOPermissionAccess.PathDiscovery.

Return to top


Property: Evidence (read-only)
Inherited
See base class member description: System.Reflection.Assembly.Evidence

Summary
Gets the evidence for this assembly.
C# Syntax:
public virtual Evidence Evidence {get;}
Implements:
IEvidenceFactory.Evidence
Remarks
Evidence is the set of information that constitutes input to security policy decisions, such as what permissions can be granted to code.
See also:
Evidence

Return to top


Property: FullName (read-only)
Inherited
See base class member description: System.Reflection.Assembly.FullName

Summary
Gets the display name of the assembly.
C# Syntax:
public virtual string FullName {get;}
Remarks
See AssemblyName for a description of the format of the display name of an assembly.
Example
            Assembly SampleAssembly;
            // Instantiate a target object.
            Int32 Integer1 = new Int32();
            Type Type1;
            // Set the Type instance to the target class type.
            Type1 = Integer1.GetType();
            // Instantiate an Assembly class to the assembly housing the Integer type.  
            SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
            // Write the display name of assembly including base name and version.
            Console.WriteLine("FullName=" + SampleAssembly.FullName);

    
See also:
MSDN: specifyingfullyqualifiedtypenames

Return to top


Property: GlobalAssemblyCache (read-only)
Inherited
See base class member description: System.Reflection.Assembly.GlobalAssemblyCache

Summary
Gets a value indicating whether the assembly was loaded from the global assembly cache.
C# Syntax:
public bool GlobalAssemblyCache {get;}

Return to top


Overridden Property: Location (read-only)
Summary
Gets the location, in codebase format, of the loaded file that contains the manifest if it is not shadow-copied.
C# Syntax:
public override string Location {get;}
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.

Return to top


Overloaded Method: AddResourceFile(
   string name,
   string fileName
)
Summary
Adds an existing resource file to this assembly.
C# Syntax:
public void AddResourceFile(
   string name,
   string fileName
);
Parameters:

name

The logical name of the resource.

fileName

The physical file name (.resources file) to which the logical name is mapped. This should not include a path.

Exceptions
Exception Type Condition
ArgumentException name has been previously defined.

-or-

There is another file in the assembly named fileName.

-or-

The length of name is zero.

-or-

The length of fileName is zero, or if fileName includes a path.

ArgumentNullException name or fileName is null.
FileNotFoundException If the file fileName is not found.
Remarks
fileName should not be the same as that of any other persistable module, standalone managed resource, or the standalone manifest file.

The managed resources in the file are assumed to be public.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission The FileIOPermissionAccess.Read permission is needed to access the resource file resourceFileName.

Return to top


Overloaded Method: AddResourceFile(
   string name,
   string fileName,
   ResourceAttributes attribute
)
Summary
Adds an existing resource file to this assembly.
C# Syntax:
public void AddResourceFile(
   string name,
   string fileName,
   ResourceAttributes attribute
);
Parameters:

name

The logical name of the resource.

fileName

The physical file name (.resources file) to which the logical name is mapped. This should not include a path.

attribute

The resource attributes.

Exceptions
Exception Type Condition
ArgumentException name has been previously defined.

-or-

There is another file in the assembly named fileName.

- or-

The length of name is zero or if the length of fileName is zero.

-or-

fileName includes a path.

ArgumentNullException name or fileName is null.
FileNotFoundException If the file fileName is not found.
Remarks
fileName should not be the same as that of any other persistable module, standalone managed resource, or the standalone manifest file.

Attributes can be specified for the managed resource.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission The FileIOPermissionAccess.Read permission is needed to access the resource file resourceFileName.

Return to top


Overloaded Method: CreateInstance(
   string typeName
)
Inherited
See base class member description: System.Reflection.Assembly.CreateInstance

Summary
Locates the specified type from this assembly and creates an instance of it using the system activator, using case-sensitive search.
C# Syntax:
public object CreateInstance(
   string typeName
);
Parameters:

typeName

The name of the type to locate.

Return Value:
An instance of Object representing the type, with culture, arguments, and binding and activation attributes set to null, or null if typeName is not found.
Exceptions
Exception Type Condition
ArgumentException typeName is the empty string ("") or "\0anything".
ArgumentNullException typeName is null.

Return to top


Overloaded Method: CreateInstance(
   string typeName,
   bool ignoreCase
)
Inherited
See base class member description: System.Reflection.Assembly.CreateInstance

Summary
Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search.
C# Syntax:
public object CreateInstance(
   string typeName,
   bool ignoreCase
);
Parameters:

typeName

The name of the type to locate.

ignoreCase

true to ignore the case of the type name; otherwise, false.

Return Value:
An instance of Object representing the type, with culture, arguments, and activation attributes set to null, and BindingFlags set to NonPublic, or null if typeName is not found.
Exceptions
Exception Type Condition
ArgumentException typeName is the empty string ("") or "\0anything".
ArgumentNullException typeName is null.

Return to top


Overloaded Method: CreateInstance(
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes
)
Inherited
See base class member description: System.Reflection.Assembly.CreateInstance

Summary
Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search and having the specified culture, arguments, and binding and activation attributes.
C# Syntax:
public object CreateInstance(
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes
);
Parameters:

typeName

The name of the type to locate.

ignoreCase

true to ignore the case of the type name; otherwise, false.

bindingAttr

A bitmask that affects the way in which the search is conducted. The value is a combination of bit flags from BindingFlags.

binder

An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects via reflection. If binder is null, the default binder is used.

args

An array of type Object containing the arguments to be passed to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to be invoked. If the default constructor is desired, args must be an empty array or null.

culture

An instance of CultureInfo used to govern the coercion of types. If this is null, the CultureInfo for the current thread is used. (This is necessary to convert a String that represents 1000 to a Double value, for example, since 1000 is represented differently by different cultures.)

activationAttributes

An array of type Object containing one or more activation attributes that can participate in the activation. An example of an activation attribute is:

URLAttribute(http://hostname/appname/objectURI)

An array of type Object containing one or more activation attributes that can participate in the activation. An example of an activation attribute is:

URLAttribute(http://hostname/appname/objectURI)

Return Value:
An instance of Object representing the type and matching the specified criteria, or null if typeName is not found.
Exceptions
Exception Type Condition
ArgumentException typeName is the empty string ("") or "\0anything".
ArgumentNullException typeName is null.
MissingFieldException The constructor cannot be found.

Return to top


Overloaded Method: DefineDynamicModule(
   string name
)
Summary
Defines a named transient dynamic module in this assembly.
C# Syntax:
public ModuleBuilder DefineDynamicModule(
   string name
);
Parameters:

name

The name of the dynamic module.

Return Value:
A ModuleBuilder representing the defined dynamic module.
Exceptions
Exception Type Condition
ArgumentException name begins with white space.

-or-

The length of name is zero.

ArgumentNullException name is null.
Remarks
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 AssemblyBuilderAccess.RunAndSave.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Overloaded Method: DefineDynamicModule(
   string name,
   bool emitSymbolInfo
)
Summary
Defines a named transient dynamic module in this assembly and specifies whether symbol information should be emitted.
C# Syntax:
public ModuleBuilder DefineDynamicModule(
   string name,
   bool emitSymbolInfo
);
Parameters:

name

The name of the dynamic module.

emitSymbolInfo

true if symbol information is to be emitted; otherwise, false.

Return Value:
A ModuleBuilder representing the defined dynamic module.
Exceptions
Exception Type Condition
ArgumentException name begins with white space.

-or-

The length of name is zero.

ArgumentNullException name is null.
ExecutionEngineException The assembly for default symbol writer cannot be loaded.

-or-

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

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

The dynamic module is not saved, even if the parent dynamic assembly was created with AssemblyBuilderAccess.RunAndSave.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Overloaded Method: DefineDynamicModule(
   string name,
   string fileName
)
Summary
Defines a dynamic module with the given name that will be saved to the specified file. No symbol information is emitted.
C# Syntax:
public ModuleBuilder DefineDynamicModule(
   string name,
   string fileName
);
Parameters:

name

The name of the dynamic module.

fileName

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

Return Value:
A ModuleBuilder object representing the defined dynamic module.
Exceptions
Exception Type Condition
ArgumentNullException name or fileName is null.
ArgumentException The length of name or fileName is zero.

-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 AssemblyBuilderAccess.Run attribute.
Remarks
To define a persistable dynamic module, this assembly needs to be created with the AssemblyBuilderAccess.Save or the AssemblyBuilderAccess.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 AssemblyBuilder.DefineDynamicModule.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission Write=true or Append=true is needed to save the module

Return to top


Overloaded Method: DefineDynamicModule(
   string name,
   string fileName,
   bool emitSymbolInfo
)
Summary
Defines a persistable dynamic module in this dynamic assembly that includes symbolic information using the default symbol writer.
C# Syntax:
public ModuleBuilder DefineDynamicModule(
   string name,
   string fileName,
   bool emitSymbolInfo
);
Parameters:

name

The name of the dynamic module.

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 null.
ArgumentException The length of name or fileName is zero.

-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 AssemblyBuilderAccess.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.

Remarks
To define a persistable dynamic module, this assembly needs to be created with the AssemblyBuilderAccess.Save or the AssemblyBuilderAccess.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 AssemblyBuilder.DefineDynamicModule.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission Write=true or Append=true is needed to save this module

Return to top


Overloaded Method: DefineResource(
   string name,
   string description,
   string fileName
)
Summary
Defines a standalone managed resource for this assembly with the default public resource attribute.
C# Syntax:
public IResourceWriter DefineResource(
   string name,
   string description,
   string fileName
);
Parameters:

name

The logical name of the resource.

description

A textual description of the resource.

fileName

The physical file name (.resources file) to which the logical name is mapped. This should not include a path.

Return Value:
A ResourceWriter object for the specified resource.
Exceptions
Exception Type Condition
ArgumentException name has been previously defined.

-or-

There is another file in the assembly named fileName.

-or-

The length of name is zero.

-or-

The length of fileName is zero.

-or-

fileName includes a path.

ArgumentNullException name or fileName is null.
Remarks
Fine grain resources can be added with the returned ResourceWriter by calling ResourceWriter.AddResource.

fileName should not be the same as that of any other persistable module, stand-alone managed resource, or the stand-alone manifest file.

The runtime calls the ResourceWriter.Close method when the dynamic assembly is saved.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission Write=true or Append=true

Return to top


Overloaded Method: DefineResource(
   string name,
   string description,
   string fileName,
   ResourceAttributes attribute
)
Summary
Defines a standalone managed resource for this assembly. Attributes can be specified for the managed resource.
C# Syntax:
public IResourceWriter DefineResource(
   string name,
   string description,
   string fileName,
   ResourceAttributes attribute
);
Parameters:

name

The logical name of the resource.

description

A textual description of the resource.

fileName

The physical file name (.resources file) to which the logical name is mapped. This should not include a path.

attribute

The resource attributes.

Return Value:
A ResourceWriter object for the specified resource.
Exceptions
Exception Type Condition
ArgumentException name has been previously defined or if there is another file in the assembly named fileName.

-or-

The length of name is zero.

-or-

The length of fileName is zero.

-or-

fileName includes a path.

ArgumentNullException name or fileName is null.
Remarks
Fine-grain resources can be added with the returned ResourceWriter by calling ResourceWriter.AddResource.

fileName should not be the same as that of any other persistable module, standalone managed resource, or the standalone manifest file.

The runtime calls the ResourceWriter.Close method when the dynamic assembly is saved.

.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true
.NET Framework Security:
FileIOPermission Write=true or Append=true

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~AssemblyBuilder();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetCustomAttributes(
   bool inherit
)
Inherited
See base class member description: System.Reflection.Assembly.GetCustomAttributes

Summary
Gets all the custom attributes for this assembly.
C# Syntax:
public virtual object[] GetCustomAttributes(
   bool inherit
);
Parameters:

inherit

This argument is ignored for objects of type Assembly.

Return Value:
An array of type Object containing the custom attributes for this assembly.
Implements:
ICustomAttributeProvider.GetCustomAttributes
Remarks
This method implements the corresponding ICustomAttributeProvider interface method. Therefore, the inherit parameter must be specified even though it is ignored.

A pseudo-attribute indicates bits of the core metadata that must be set when the attribute is present. Unlike a custom attribute that extends the metadata for a type and is saved along with the type, a pseudo-attribute modifies the metadata for the type and then is discarded. Some of the resulting bits cannot be accessed using existing reflection APIs.

The following table summarizes the different pseudo-attributes and the accessors for the bits that are available in reflection.



Pseudo-Attribute Metadata Bits Reflection Accessor
DllImportAttribute CorPInvokeMap DLL name No accessor for PInvokeMap for ordinary method/global method attributes. No accessor for DLL name.
GuidAttribute Stored as a real custom attribute. Accessed as a real custom attribute.
ComImportAttribute CorTypeAttr.tdImport Type.Attributes.Import
SerializableAttribute CorTypeAttr.tdSerializable Type.Attributes.Serializable
NonSerializedAttribute CorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerialized
MethodImplAttribute CorMethodImpl MethodInfo.GetMethodImplementationFlags() ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttribute Various bits. No accessor.
PreserveSigAttribute CorMethodImpl.miOLE MethodInfo.GetMethodImplementationFlags().OLE ConstructorInfo.GetMethodImplementationFlags().OLE
InAttribute CorParamAttr.pdIn ParameterInfo.Attributes.In
OutAttribute CorParamAttr.pdOut ParameterInfo.Attributes.Out
StructLayoutAttribute CorTypeAttr.tdLayoutSequential CorTypeAttr.tdExplicitLayout CorTypeAttr.tdAnsiClass CorTypeAttr.tdUnicodeClass CorTypeAttr.tdAutoClass Class packing. Type.Attributes.LayoutSequential Type.Attributes.ExplicitLayout Type.Attributes.AnsiClass Type.Attributes.UnicodeClass Type.Attributes.AutoClass No accessor.
FieldOffsetAttribute Field offset. No accessor.
AssemblyLoadAttribute CorAssemblyFlags No accessor or enumerator.

Return to top


Overloaded Method: GetCustomAttributes(
   Type attributeType,
   bool inherit
)
Inherited
See base class member description: System.Reflection.Assembly.GetCustomAttributes

Summary
Gets the custom attributes for this assembly as specified by type.
C# Syntax:
public virtual object[] GetCustomAttributes(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

The Type for which the custom attributes are to be returned.

inherit

This argument is ignored for objects of type Assembly.

Return Value:
An array of type Object containing the custom attributes for this assembly as specified by attributeType.
Exceptions
Exception Type Condition
ArgumentNullException attributeType is null.
ArgumentException attributeType is not a runtime type.
Implements:
ICustomAttributeProvider.GetCustomAttributes
Remarks
This method implements the corresponding ICustomAttributeProvider interface method. Therefore, the inherit parameter must be specified even though it is ignored.

Return to top


Method: GetDynamicModule(
   string name
)
Summary
Returns the dynamic module with the specified name.
C# Syntax:
public ModuleBuilder GetDynamicModule(
   string name
);
Parameters:

name

The name of the requested dynamic module.

Return Value:
A ModuleBuilder object representing the requested dynamic module.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
ArgumentException The length of name is zero.

Return to top


Overridden Method: GetExportedTypes()
Summary
Gets the exported types defined in this assembly.
C# Syntax:
public override Type[] GetExportedTypes();
Return Value:
An array of Type containing the exported types defined in this assembly.
Exceptions
Exception Type Condition
NotSupportedException This method is not implemented.

Return to top


Overridden Method: GetFile(
   string name
)
Summary
Gets a FileStream for the specified file in the file table of the manifest of this assembly.
C# Syntax:
public override FileStream GetFile(
   string name
);
Parameters:

name

The name of the specified file.

Return Value:
A FileStream for the specified file, or null, if the file is not found.
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.
Remarks
name should not include the path to the file.

Return to top


Overloaded Method: GetFiles()
Inherited
See base class member description: System.Reflection.Assembly.GetFiles

Summary
Gets the files in the file table of an assembly manifest.
C# Syntax:
public virtual FileStream[] GetFiles();
Return Value:
An array of FileStream objects.
Remarks
This method only works on public resources.

Return to top


Overloaded Method: GetFiles(
   bool getResourceModules
)
Summary
Gets the files in the file table of an assembly manifest, specifying whether to include resource modules.
C# Syntax:
public override FileStream[] GetFiles(
   bool getResourceModules
);
Parameters:

getResourceModules

true to include resource modules; otherwise, false.

Return Value:
An array of FileStream objects.
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetLoadedModules()
Inherited
See base class member description: System.Reflection.Assembly.GetLoadedModules

Summary
Gets all the loaded modules that are part of this assembly.
C# Syntax:
public Module[] GetLoadedModules();
Return Value:
An array of modules.
Remarks
A type can be retrieved from a specific module using Module.GetType. Calling Module.GetType on the module containing the manifest will not initiate a search of the entire assembly. To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.

Return to top


Overloaded Method: GetLoadedModules(
   bool getResourceModules
)
Inherited
See base class member description: System.Reflection.Assembly.GetLoadedModules

Summary
Gets all the loaded modules that are part of this assembly, specifying whether to include resource modules.
C# Syntax:
public Module[] GetLoadedModules(
   bool getResourceModules
);
Parameters:

getResourceModules

true to include resource modules; otherwise, false.

Return Value:
An array of modules.

Return to top


Overridden Method: GetManifestResourceInfo(
   string resourceName
)
Summary
Returns information about how the given resource has been persisted.
C# Syntax:
public override ManifestResourceInfo GetManifestResourceInfo(
   string resourceName
);
Parameters:

resourceName

The name of the resource.

Return Value:
ManifestResourceInfo populated with information about the resource's topology, or null if the resource is not found.
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.

Return to top


Overridden Method: GetManifestResourceNames()
Summary
Loads the specified manifest resource from this assembly.
C# Syntax:
public override string[] GetManifestResourceNames();
Return Value:
An array of type String containing the names of all the resources.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported on a dynamic assembly. To get the manifest resource names, use Assembly.GetManifestResourceNames.

Return to top


Overloaded Method: GetManifestResourceStream(
   string name
)
Summary
Loads the specified manifest resource from this assembly.
C# Syntax:
public override Stream GetManifestResourceStream(
   string name
);
Parameters:

name

The name of the manifest resource being requested.

Return Value:
A Stream representing this manifest resource.
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.

Return to top


Overloaded Method: GetManifestResourceStream(
   Type type,
   string name
)
Summary
Loads the specified manifest resource, scoped by the namespace of the specified type, from this assembly.
C# Syntax:
public override Stream GetManifestResourceStream(
   Type type,
   string name
);
Parameters:

type

The type whose namespace is used to scope the manifest resource name.

name

The name of the manifest resource being requested.

Return Value:
A Stream representing this manifest resource.
Exceptions
Exception Type Condition
NotSupportedException This method is not currently supported.
Remarks
The returned Stream has its file pointer set to the beginning of the resource.
Example
If the full name of type is "MyNameSpace.MyClasses" and name is "Dot", GetManifestResourceStream will search for a resource named MyNameSpace.Dot.
See also:
MSDN: assemblymanifest

Return to top


Method: GetModule(
   string name
)
Inherited
See base class member description: System.Reflection.Assembly.GetModule

Summary
Gets the specified module in this assembly.
C# Syntax:
public Module GetModule(
   string name
);
Parameters:

name

The name of the module being requested.

Return Value:
The Module being requested.
Remarks
This method works on file names.

Classes in the Reflection.Emit namespace emit the scope name for a dynamic module. The scope name can be determined by the Module.ScopeName property. Pass the kind of module you want to Assembly.GetModule. For example, if you want the module that contains the assembly manifest, pass the scope name of the module to GetModule. Otherwise, pass the file name of the module. Assemblies loaded by one of the Load methods that have a byte[] parameter have only one module, and that is the manifest module. Always seek these modules using the scope name.

A type can be retrieved from a specific module using Module.GetType. Calling Module.GetType on the module containing the manifest will not initiate a search of the entire assembly. To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.

Return to top


Overloaded Method: GetModules()
Inherited
See base class member description: System.Reflection.Assembly.GetModules

Summary
Gets all the modules that are part of this assembly.
C# Syntax:
public Module[] GetModules();
Return Value:
An array of modules.
Exceptions
Exception Type Condition
FileNotFoundException The module to be loaded does not specify a file name extension.
Remarks
A type can be retrieved from a specific module using Module.GetType. Calling Module.GetType on the module containing the manifest will not initiate a search of the entire assembly. To retrieve a type from an assembly, regardless of which module it is in, you must call Assembly.GetType.

Note Modules must be emitted with file name extensions.
Example
The first module in the returned array contains the assembly's manifest. So, the following code fragment gets the manifest module:
 Assembly mainAssembly = Assembly.GetExecutingAssembly();
 Module mainMod = mainAssembly.GetModules()[0];

    

Return to top


Overloaded Method: GetModules(
   bool getResourceModules
)
Inherited
See base class member description: System.Reflection.Assembly.GetModules

Summary
Gets all the modules that are part of this assembly, specifying whether to include resource modules.
C# Syntax:
public Module[] GetModules(
   bool getResourceModules
);
Parameters:

getResourceModules

true to include resource modules; otherwise, false.

Return Value:
An array of modules.
Remarks


Note Modules must be emitted with file name extensions.

Return to top


Overloaded Method: GetName()
Inherited
See base class member description: System.Reflection.Assembly.GetName

Summary
Gets an AssemblyName for this assembly.
C# Syntax:
public virtual AssemblyName GetName();
Return Value:
An AssemblyName for this assembly.

Return to top


Overloaded Method: GetName(
   bool copiedName
)
Inherited
See base class member description: System.Reflection.Assembly.GetName

Summary
Gets an AssemblyName for this assembly, setting the codebase as specified by copiedName.
C# Syntax:
public virtual AssemblyName GetName(
   bool copiedName
);
Parameters:

copiedName

true to set the Assembly.CodeBase to the location of the assembly after it was shadow copied; false to set Assembly.CodeBase to the original location.

Return Value:
An AssemblyName for this assembly.

Return to top


Method: GetObjectData(
   SerializationInfo info,
   StreamingContext context
)
Inherited
See base class member description: System.Reflection.Assembly.GetObjectData

Summary
Gets serialization information with all of the data needed to reinstantiate this assembly.
C# Syntax:
public virtual void GetObjectData(
   SerializationInfo info,
   StreamingContext context
);
Parameters:

info

The object to be populated with serialization information.

context

The destination context of the serialization.

Exceptions
Exception Type Condition
ArgumentNullException info is null.
Implements:
ISerializable.GetObjectData

Return to top


Method: GetReferencedAssemblies()
Inherited
See base class member description: System.Reflection.Assembly.GetReferencedAssemblies

Summary
Gets the AssemblyName objects for all the assemblies referenced by this assembly.
C# Syntax:
public AssemblyName[] GetReferencedAssemblies();
Return Value:
An array of type AssemblyName containing all the assemblies referenced by this assembly.

Return to top


Overloaded Method: GetSatelliteAssembly(
   CultureInfo culture
)
Inherited
See base class member description: System.Reflection.Assembly.GetSatelliteAssembly

Summary
Gets the satellite assembly for the specified culture.
C# Syntax:
public Assembly GetSatelliteAssembly(
   CultureInfo culture
);
Parameters:

culture

The specified culture.

Return Value:
The specified satellite assembly.
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
FileNotFoundException The assembly cannot be found.
FileLoadException The satellite assembly with a matching file name was found, but the CultureInfo did not match the one specified.
Remarks
Satellite assemblies contain localized resources, as distinct from main application assemblies, which contain non-localizable executable code and resources for a single culture that serve as the default or neutral culture.

Call this method to use your current assembly version.

Return to top


Overloaded Method: GetSatelliteAssembly(
   CultureInfo culture,
   Version version
)
Inherited
See base class member description: System.Reflection.Assembly.GetSatelliteAssembly

Summary
Gets the specified version of the satellite assembly for the specified culture.
C# Syntax:
public Assembly GetSatelliteAssembly(
   CultureInfo culture,
   Version version
);
Parameters:

culture

The specified culture.

version

The version of the satellite assembly.

Return Value:
The specified satellite assembly.
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
FileLoadException The satellite assembly with a matching file name was found, but the CultureInfo or the version did not match the one specified.
FileNotFoundException The assembly cannot be found.
Remarks
Satellite assemblies contain localized resources, as distinct from main application assemblies, which contain non-localizable executable code and resources for a single culture that serve as the default or neutral culture.

Call GetSatelliteAssembly to use your current assembly version.

If version is null, the current assembly version is used if both the resource and main assemblies are signed.

Return to top


Overloaded Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetType(
   string name
)
Inherited
See base class member description: System.Reflection.Assembly.GetType

Summary
Gets the Type object with the specified name in the assembly instance.
C# Syntax:
public virtual Type GetType(
   string name
);
Parameters:

name

The full name of the type.

Return Value:
A Type object that represents the specified class.
Exceptions
Exception Type Condition
ReflectionTypeLoadException The type is not in the assembly instance you are calling the method on.
ArgumentException name is invalid.
ArgumentNullException name is null.
SecurityException The caller does not have the required permission.
Remarks
Unlike Type.GetType, which requires a string that includes both the type name and the assembly name, this method requires only the type name because only the assembly on which you are calling GetType is used.
.NET Framework Security:
ReflectionPermission for reflecting methods that are not public. Associated enumerations: ReflectionPermissionFlag.MemberAccess, ReflectionPermissionFlag.TypeInformation

Return to top


Overloaded Method: GetType(
   string name,
   bool throwOnError
)
Inherited
See base class member description: System.Reflection.Assembly.GetType

Summary
Gets the Type object with the specified name in the assembly instance and optionally throws an exception.
C# Syntax:
public virtual Type GetType(
   string name,
   bool throwOnError
);
Parameters:

name

The full name of the type.

throwOnError

true to throw an exception if the type is not found; otherwise, null.

Return Value:
A Type object that represents the specified class.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
Remarks
Unlike Type.GetType, which requires a string that includes both the type name and the assembly name, this method requires only the type name because only the assembly on which you are calling GetType is used.
.NET Framework Security:
ReflectionPermission for reflecting methods that are not public. Associated enumerations: ReflectionPermissionFlag.MemberAccess, ReflectionPermissionFlag.TypeInformation

Return to top


Overloaded Method: GetType(
   string name,
   bool throwOnError,
   bool ignoreCase
)
Inherited
See base class member description: System.Reflection.Assembly.GetType

Summary
Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and throwing an exception.
C# Syntax:
public Type GetType(
   string name,
   bool throwOnError,
   bool ignoreCase
);
Parameters:

name

The full name of the type.

throwOnError

true to throw an exception if the type is not found; otherwise, null.

ignoreCase

true to ignore the case of the type name; otherwise, false.

Return Value:
A Type object that represents the specified class.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
Remarks
Unlike Type.GetType, which requires a string that includes both the type name and the assembly name, this method requires only the type name because only the assembly on which you are calling GetType is used.
.NET Framework Security:
ReflectionPermission for reflecting methods that are not public. Associated enumerations: ReflectionPermissionFlag.MemberAccess, ReflectionPermissionFlag.TypeInformation

Return to top


Method: GetTypes()
Inherited
See base class member description: System.Reflection.Assembly.GetTypes

Summary
Gets the types defined in this assembly.
C# Syntax:
public virtual Type[] GetTypes();
Return Value:
An array of type Type containing objects for all the types defined in this assembly.
Example
            Assembly SampleAssembly;
            SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
            // Obtain a reference to a method known to exist in assembly.
            MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
            // Obtain a reference to the parameters collection of the MethodInfo instance.
            ParameterInfo[] Params = Method.GetParameters();
            // Display information about method parameters.
            // Param = sParam1
            //   Type = System.String
            //   Position = 0
            //   Optional=False
            foreach (ParameterInfo Param in Params){
                Console.WriteLine("Param=" + Param.Name.ToString());
                Console.WriteLine("  Type=" + Param.ParameterType.ToString());
                Console.WriteLine("  Position=" + Param.Position.ToString());
                Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
            }

    
.NET Framework Security:
ReflectionPermission for reflecting methods that are not public. Associated enumerations: ReflectionPermissionFlag.MemberAccess, ReflectionPermissionFlag.TypeInformation

Return to top


Method: IsDefined(
   Type attributeType,
   bool inherit
)
Inherited
See base class member description: System.Reflection.Assembly.IsDefined

Summary
Indicates whether a custom attribute identified by the specified Type is defined.
C# Syntax:
public virtual bool IsDefined(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

The Type for which the custom attributes are to be checked.

inherit

This argument is ignored for objects of this type.

Return Value:
true if a custom attribute identified by the specified Type is defined; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException attributeType is null.
Implements:
ICustomAttributeProvider.IsDefined

Return to top


Overloaded Method: LoadModule(
   string moduleName,
   byte[] rawModule
)
Inherited
See base class member description: System.Reflection.Assembly.LoadModule

Summary
Loads the module, internal to this assembly, with a Common Object File Format (COFF)-based image containing an emitted module, or a resource file.
C# Syntax:
public Module LoadModule(
   string moduleName,
   byte[] rawModule
);
Parameters:

moduleName

Name of the module. Must correspond to a File name in this assembly's manifest.

rawModule

An array of type byte that is a COFF-based image containing an emitted module, or a resource.

Return Value:
The loaded Module.
Exceptions
Exception Type Condition
ArgumentNullException moduleName or rawModule is null.
ArgumentException moduleName does not match a File entry in this assembly's manifest.
BadImageFormatException rawModule is not a valid module.
SecurityException The caller does not have the required permission.
.NET Framework Security:
SecurityPermission to provide evidence. Associated enumeration: SecurityPermissionFlag.ControlEvidence.

Return to top


Overloaded Method: LoadModule(
   string moduleName,
   byte[] rawModule,
   byte[] rawSymbolStore
)
Inherited
See base class member description: System.Reflection.Assembly.LoadModule

Summary
Loads the module, internal to this assembly, with a Common Object File Format (COFF)-based image containing an emitted module, or a resource file. The raw bytes representing the symbols for the module are also loaded.
C# Syntax:
public Module LoadModule(
   string moduleName,
   byte[] rawModule,
   byte[] rawSymbolStore
);
Parameters:

moduleName

Name of the module. Must correspond to a File name in this assembly's manifest.

rawModule

An array of type byte that is a COFF-based image containing an emitted module, or a resource.

rawSymbolStore

An array of type byte containing the raw bytes representing the symbols for the module. Must be null if this is a resource file.

Return Value:
The loaded Module.
Exceptions
Exception Type Condition
ArgumentNullException moduleName or rawModule is null.
ArgumentException moduleName does not match a File entry in this assembly's manifest.
BadImageFormatException rawModule is not a valid module.
SecurityException The caller does not have the required permission.
.NET Framework Security:
SecurityPermission to provide evidence. Associated enumeration: SecurityPermissionFlag.ControlEvidence.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Save(
   string assemblyFileName
)
Summary
Saves this dynamic assembly to disk.
C# Syntax:
public void Save(
   string assemblyFileName
);
Parameters:

assemblyFileName

The file name of the assembly.

Exceptions
Exception Type Condition
ArgumentException The length of assemblyFileName is 0.

-or-

There are two or more modules resource files in the assembly with the same name.

-or-

The target directory of the assembly is invalid.

-or-

assemblyFileName is not a simple file name (for example, has a directory or drive component) or more than unmanaged resource, including version information resource, was defined in this assembly.

-or-

The CultureInfo string in AssemblyCultureAttribute is not a valid string and System.Reflection.Emit.AssemblyBuilder.DefineVersionInfoResource (not supported on the shared source CLI) was called prior to calling this method.

ArgumentNullException assemblyFileName is null.
InvalidOperationException This assembly has been saved before.

-or-

This assembly has access Run AssemblyBuilderAccess

IOException If any output error occurs during the save.
NotSupportedException If TypeBuilder.CreateType has not been called for any of the types in the modules of the assembly to be written to disk.
Remarks
This method saves all non-transient dynamic modules defined in this dynamic assembly. Transient dynamic modules are not saved. The assembly file name can be the same as one of the module's name. If so, the assemby information is stored within that module.assemblyFileName can be different from the names of all of the modules contained within the assembly. If so, the assembly is stored as a standalone.

For each ResourceWriter obtained using AssemblyBuilder.DefineResource, this method writes the .resources file and calls ResourceWriter.Close to close the stream.

The assemblyFileName needs to be a simple file name without a drive or directory component. To create an assembly in a specific directory, use one of the AppDomain.DefineDynamicAssembly methods that takes a target directory argument.

.NET Framework Security:
FileIOPermission Write = true or Append = true is needed to save this assembly to the specified file name.

Return to top


Overloaded Method: SetCustomAttribute(
   CustomAttributeBuilder customBuilder
)
Summary
Set a custom attribute on this assembly using a custom attribute builder.
C# Syntax:
public void SetCustomAttribute(
   CustomAttributeBuilder customBuilder
);
Parameters:

customBuilder

An instance of a helper class to define the custom attribute.

Exceptions
Exception Type Condition
ArgumentNullException con is null.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Overloaded Method: SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
)
Summary
Set a custom attribute on this assembly using a specified custom attribute blob.
C# Syntax:
public void SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
);
Parameters:

con

The constructor for the custom attribute.

binaryAttribute

A byte blob representing the attributes.

Exceptions
Exception Type Condition
ArgumentNullException con or binaryAttribute is null.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Overloaded Method: SetEntryPoint(
   MethodInfo entryMethod
)
Summary
Sets the entry point for this dynamic assembly, assuming that a console application is being built.
C# Syntax:
public void SetEntryPoint(
   MethodInfo entryMethod
);
Parameters:

entryMethod

A reference to the method that represents the entry point for this dynamic assembly.

Exceptions
Exception Type Condition
ArgumentNullException entryMethod is null.
InvalidOperationException entryMethod is not contained within this assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Overloaded Method: SetEntryPoint(
   MethodInfo entryMethod,
   PEFileKinds fileKind
)
Summary
Sets the entry point for this assembly and defines the type of the PE being built.
C# Syntax:
public void SetEntryPoint(
   MethodInfo entryMethod,
   PEFileKinds fileKind
);
Parameters:

entryMethod

A reference to the method that represents the entry point for this dynamic assembly.

fileKind

The type of the assembly executable being built.

Exceptions
Exception Type Condition
ArgumentNullException entryMethod is null.
InvalidOperationException entryMethod is not contained within this assembly.
.NET Framework Security:
ReflectionPermission SecurityAction.Demand, ReflectionEmit=true

Return to top


Method: ToString()
Inherited
See base class member description: System.Reflection.Assembly.ToString

Summary
Returns the full name of the assembly, also known as the display name.
C# Syntax:
public override string ToString();
Return Value:
The full name of the assembly, or the class name if the full name of the assembly cannot be determined.

Return to top


Event: ModuleResolve
Inherited
See base class member description: System.Reflection.Assembly.ModuleResolve

Summary
Occurs when the common language runtime class loader cannot resolve a reference to an internal module of an assembly through normal means.
C# Syntax:
public event ModuleResolveEventHandler ModuleResolve;
Remarks
This event gives the callback a chance to find and load the module itself and return it.
.NET Framework Security:
SecurityPermission to create and manipulate an application domain. Associated enumeration: SecurityPermissionFlag.ControlAppDomain.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.