Don't close the stream when reading AssemblyMetadata

This commit is contained in:
David Fowler 2014-09-26 03:06:02 -07:00
parent 3cd6d3e060
commit 8b62057aa3
1 changed files with 6 additions and 9 deletions

View File

@ -20,8 +20,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
/// </summary>
public class RoslynCompilationService : ICompilationService
{
private readonly ConcurrentDictionary<string, MetadataReference> _metadataFileCache =
new ConcurrentDictionary<string, MetadataReference>(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache =
new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase);
private readonly ILibraryManager _libraryManager;
private readonly IApplicationEnvironment _environment;
@ -172,15 +172,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
private MetadataReference CreateMetadataFileReference(string path)
{
return _metadataFileCache.GetOrAdd(path, _ =>
var metadata = _metadataFileCache.GetOrAdd(path, _ =>
{
// TODO: What about access to the file system? We need to be able to
// read files from anywhere on disk, not just under the web root
using (var stream = File.OpenRead(path))
{
return new MetadataImageReference(stream);
}
return AssemblyMetadata.CreateFromImageStream(File.OpenRead(path));
});
return new MetadataImageReference(metadata);
}
private static CompilationMessage GetCompilationMessage(DiagnosticFormatter formatter, Diagnostic diagnostic)