Export (0) Print
Expand All

AssemblyBuilder.Save Method (String, PortableExecutableKinds, ImageFileMachine)

Saves this dynamic assembly to disk, specifying the nature of code in the assembly's executables and the target platform.

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

public void Save(
	string assemblyFileName,
	PortableExecutableKinds portableExecutableKind,
	ImageFileMachine imageFileMachine
)

Parameters

assemblyFileName
Type: System.String

The file name of the assembly.

portableExecutableKind
Type: System.Reflection.PortableExecutableKinds

A bitwise combination of the PortableExecutableKinds values that specifies the nature of the code.

imageFileMachine
Type: System.Reflection.ImageFileMachine

One of the ImageFileMachine values that specifies the target platform.

ExceptionCondition
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 one unmanaged resource, including a version information resources, was defined in this assembly.

-or-

The CultureInfo string in AssemblyCultureAttribute is not a valid string and DefineVersionInfoResource 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

An output error occurs during the save.

NotSupportedException

CreateType has not been called for any of the types in the modules of the assembly to be written to disk.

If imageFileMachine and portableExecutableKind are incompatible, imageFileMachine takes precedence over portableExecutableKind. No exception is thrown. For example, if you specify ImageFileMachine.I386 with PortableExecutableKinds.PE32Plus, PortableExecutableKinds.PE32Plus is ignored.

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 the name of one of the module. If so, the assembly manifest 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 file contains only the assembly manifest.

For each ResourceWriter obtained using DefineResource, this method writes the .resources file and calls 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 DefineDynamicAssembly methods that takes a target directory argument.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft