MetadataReference.CreateFromFile Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a reference to an assembly or standalone module stored in a file. Reads the content of the file into memory.
public static Microsoft.CodeAnalysis.PortableExecutableReference CreateFromFile (string path, Microsoft.CodeAnalysis.MetadataReferenceProperties properties = default, Microsoft.CodeAnalysis.DocumentationProvider documentation = default);
public static Microsoft.CodeAnalysis.PortableExecutableReference CreateFromFile (string path, Microsoft.CodeAnalysis.MetadataReferenceProperties properties = default, Microsoft.CodeAnalysis.DocumentationProvider? documentation = default);
static member CreateFromFile : string * Microsoft.CodeAnalysis.MetadataReferenceProperties * Microsoft.CodeAnalysis.DocumentationProvider -> Microsoft.CodeAnalysis.PortableExecutableReference
Public Shared Function CreateFromFile (path As String, Optional properties As MetadataReferenceProperties = Nothing, Optional documentation As DocumentationProvider = Nothing) As PortableExecutableReference
Parameters
- path
- String
Path to the assembly file.
- properties
- MetadataReferenceProperties
Reference properties (extern aliases, type embedding, MetadataImageKind).
- documentation
- DocumentationProvider
Provides XML documentation for symbol found in the reference.
Returns
Exceptions
path
is null.
path
is invalid.
An error occurred while reading the file.
Remarks
Performance considerations:
It is recommended to use CreateFromFile(String) or CreateFromFile(String) API when creating multiple references to the same file. Reusing Metadata object allows for sharing data across these references.
The method eagerly reads the entire content of the file 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 CreateFromFile(String) to create an IDisposable metadata object and GetReference(DocumentationProvider, ImmutableArray<String>, Boolean, String, String) to get a reference to it.