Delen via


MetadataReference.CreateFromStream Method

Definition

Creates a reference to a single-module assembly or a stand-alone module from data in specified stream. Reads the content of the stream into memory and closes the stream upon return.

public static Microsoft.CodeAnalysis.PortableExecutableReference CreateFromStream (System.IO.Stream peStream, Microsoft.CodeAnalysis.MetadataReferenceProperties properties = default, Microsoft.CodeAnalysis.DocumentationProvider documentation = default, string filePath = default);
public static Microsoft.CodeAnalysis.PortableExecutableReference CreateFromStream (System.IO.Stream peStream, Microsoft.CodeAnalysis.MetadataReferenceProperties properties = default, Microsoft.CodeAnalysis.DocumentationProvider? documentation = default, string? filePath = default);
static member CreateFromStream : System.IO.Stream * Microsoft.CodeAnalysis.MetadataReferenceProperties * Microsoft.CodeAnalysis.DocumentationProvider * string -> Microsoft.CodeAnalysis.PortableExecutableReference
Public Shared Function CreateFromStream (peStream As Stream, Optional properties As MetadataReferenceProperties = Nothing, Optional documentation As DocumentationProvider = Nothing, Optional filePath As String = Nothing) As PortableExecutableReference

Parameters

peStream
Stream

Assembly image.

properties
MetadataReferenceProperties

Reference properties (extern aliases, type embedding, MetadataImageKind).

documentation
DocumentationProvider

Provides XML documentation for symbol found in the reference.

filePath
String

Optional path that describes the location of the metadata. The file doesn't need to exist on disk. The path is opaque to the compiler.

Returns

Exceptions

peStream doesn't support read and seek operations.

peStream is null.

An error occurred while reading the stream.

Remarks

Performance considerations:

It is recommended to use CreateFromStream(Stream, PEStreamOptions) or CreateFromStream(Stream, PEStreamOptions) API when creating multiple references to the same metadata. Reusing Metadata object to create multiple references allows for sharing data across these references.

The method eagerly reads the entire content of peStream into native heap. The native memory block is released when the resulting reference becomes unreachable and GC collects it. To decrease memory footprint of the reference and/or manage the lifetime deterministically use CreateFromStream(Stream, PEStreamOptions) to create an IDisposable metadata object and GetReference(DocumentationProvider, ImmutableArray<String>, Boolean, String, String) to get a reference to it.

Applies to