From 8b62057aa3a691528c94247ee154f1f626951b85 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 26 Sep 2014 03:06:02 -0700 Subject: [PATCH] Don't close the stream when reading AssemblyMetadata --- .../Compilation/RoslynCompilationService.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index 6f9abe6170..dfe3c96be9 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -20,8 +20,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation /// public class RoslynCompilationService : ICompilationService { - private readonly ConcurrentDictionary _metadataFileCache = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _metadataFileCache = + new ConcurrentDictionary(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)