Use NonDisposableStream instead of using MemoryStream.ToArray()
This commit is contained in:
parent
39ab9badde
commit
9a5ebf1497
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FileProviders;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
using Microsoft.AspNet.Mvc.Internal;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||||
|
|
@ -92,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||||
var file = filesToProcess[index];
|
var file = filesToProcess[index];
|
||||||
|
|
||||||
PrecompilationCacheEntry cacheEntry;
|
PrecompilationCacheEntry cacheEntry;
|
||||||
if(!PreCompilationCache.TryGetValue(file.RelativePath, out cacheEntry))
|
if (!PreCompilationCache.TryGetValue(file.RelativePath, out cacheEntry))
|
||||||
{
|
{
|
||||||
cacheEntry = GetCacheEntry(file);
|
cacheEntry = GetCacheEntry(file);
|
||||||
PreCompilationCache.Set(
|
PreCompilationCache.Set(
|
||||||
|
|
@ -163,10 +164,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assemblyStream.Position = 0;
|
|
||||||
var assemblyBytes = assemblyStream.ToArray();
|
|
||||||
var assemblyResource = new ResourceDescription(assemblyResourceName,
|
var assemblyResource = new ResourceDescription(assemblyResourceName,
|
||||||
() => new MemoryStream(assemblyBytes),
|
() => GetNonDisposableStream(assemblyStream),
|
||||||
isPublic: true);
|
isPublic: true);
|
||||||
CompileContext.Resources.Add(assemblyResource);
|
CompileContext.Resources.Add(assemblyResource);
|
||||||
|
|
||||||
|
|
@ -174,11 +173,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||||
if (pdbStream != null)
|
if (pdbStream != null)
|
||||||
{
|
{
|
||||||
symbolsResourceName = resourcePrefix + ".pdb";
|
symbolsResourceName = resourcePrefix + ".pdb";
|
||||||
pdbStream.Position = 0;
|
|
||||||
var pdbBytes = pdbStream.ToArray();
|
|
||||||
|
|
||||||
var pdbResource = new ResourceDescription(symbolsResourceName,
|
var pdbResource = new ResourceDescription(symbolsResourceName,
|
||||||
() => new MemoryStream(pdbBytes),
|
() => GetNonDisposableStream(pdbStream),
|
||||||
isPublic: true);
|
isPublic: true);
|
||||||
|
|
||||||
CompileContext.Resources.Add(pdbResource);
|
CompileContext.Resources.Add(pdbResource);
|
||||||
|
|
@ -279,6 +275,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Stream GetNonDisposableStream(Stream stream)
|
||||||
|
{
|
||||||
|
stream.Position = 0;
|
||||||
|
return new NonDisposableStream(stream);
|
||||||
|
}
|
||||||
|
|
||||||
private class PrecompileRazorFileInfoCollection : RazorFileInfoCollection
|
private class PrecompileRazorFileInfoCollection : RazorFileInfoCollection
|
||||||
{
|
{
|
||||||
public PrecompileRazorFileInfoCollection(string assemblyResourceName,
|
public PrecompileRazorFileInfoCollection(string assemblyResourceName,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue