Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Save Method (String, PortableExecutableKinds, ImageFileMachine)
Collapse the table of content
Expand the table of content

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


Type: System.String

The file name of the assembly.

Type: System.Reflection.PortableExecutableKinds

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

Type: System.Reflection.ImageFileMachine

One of the ImageFileMachine values that specifies the target platform.


The length of assemblyFileName is 0.


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


The target directory of the assembly is invalid.


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.


The CultureInfo string in AssemblyCultureAttribute is not a valid string and DefineVersionInfoResource was called prior to calling this method.


assemblyFileName is null.


This assembly has been saved before.


This assembly has access Run AssemblyBuilderAccess


An output error occurs during the save.


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

© 2015 Microsoft