ModuleBuilder::DefineManifestResource Method (String^, Stream^, ResourceAttributes)

 

Defines a binary large object (BLOB) that represents a manifest resource to be embedded in the dynamic assembly.

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

public:
void DefineManifestResource(
	String^ name,
	Stream^ stream,
	ResourceAttributes attribute
)

Parameters

name
Type: System::String^

The case-sensitive name for the resource.

stream
Type: System.IO::Stream^

A stream that contains the bytes for the resource.

attribute
Type: System.Reflection::ResourceAttributes

An enumeration value that specifies whether the resource is public or private.

Exception Condition
ArgumentNullException

name is null.

-or-

stream is null.

ArgumentException

name is a zero-length string.

InvalidOperationException

The dynamic assembly that contains the current module is transient; that is, no file name was specified when DefineDynamicModule was called.

Resources that are recorded in the assembly manifest can be managed resources or manifest resource BLOBs, and each of these can be included in the assembly either by linking or by embedding. All four scenarios are supported for dynamic assemblies.

In addition, a single Win32 resource can be attached to an assembly by using the AssemblyBuilder::DefineUnmanagedResource method or the ModuleBuilder::DefineUnmanagedResource method. This resource does not appear in the assembly manifest.

The following example generates and saves a dynamic assembly named EmittedManifestResourceAssembly.exe, which contains an embedded unmanaged resource. The example creates the assembly, which consists of one module, and opens a memory stream to contain the unmanaged resource. The code then calls the DefineManifestResource method to define the resource.

System_CAPS_noteNote

You can use any kind of stream for your resource; for example, you can read the unmanaged binary data from a file.

The example defines a type in the dynamic module with a Main method, and generates MSIL for the method body. After the body for the Main method has been generated and the type has been created, the code example writes five bytes to the stream associated with the manifest resource. When the assembly is saved, the resource is appended to it.

After running the example, you can run the emitted assembly. The code in the emitted assembly's Main method reads the embedded manifest resource and prints the byte values to the console. You can use the Ildasm.exe (IL Disassembler) to view the information in the assembly manifest.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Return to top
Show: