• T
    AssemblyMetadata and ModuleMetadata factories should not read the content of... · 06979fd8
    TomasMatousek 提交于
     AssemblyMetadata and ModuleMetadata factories should not read the content of the PE file/metadata blob.
    
         Currently the factories read the headers, Assembly and Modules tables, which might result in BadImageFormatException being thrown. This exception is not turned into a compilation diagnostic because it happens before the compilation is created. A user of the Roslyn API thus needs to handle these errors in two places (as an exception and as a diagnostics). The content reading should be deferred until the AssemblyMetadata/ModuleMetadata is queried for content.
    
         This change defers metadata/PE headers reading and decoding until the AssemblyMetadata and ModuleMetadata properties/methods are called.
         For metadata created from files it aims to match the usage pattern of other APIs working with FileStream. The metadata factory opens the file, which might throw IO exception, but doesn't start reading the stream until the compiler asks for it, therefore it doesn't throw BadImageFormatException. The functionality is equivalent to the user opening a FileStream and creating metadata from that stream (except for a slight complication with multi-module assemblies, which are rare). Thus the API for metadata creation are consistent among in-memory byte array, stream, and file path.  (changeset 1342462)
    06979fd8
ModuleMetadata.cs 10.6 KB