else
{
// The peImage is left null, but the lazyMetadataBlock is initialized up front.
- _lazyPEHeaders = new PEHeaders(peStream);
+ _lazyPEHeaders = new PEHeaders(peStream, actualSize, IsLoadedImage);
_lazyMetadataBlock = StreamMemoryBlockProvider.ReadMemoryBlockNoLock(peStream, _lazyPEHeaders.MetadataStartOffset, _lazyPEHeaders.MetadataSize);
}
// We read all we need, the stream is going to be closed.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
using System.Collections.Immutable;
using System.IO;
+using System.Reflection.Internal;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.Metadata.Tests;
using System.Runtime.CompilerServices;
+using Microsoft.Win32.SafeHandles;
using Xunit;
namespace System.Reflection.PortableExecutable.Tests
Assert.Equal(@"Debug", reader.GetString(reader.GetAssemblyDefinition().Name));
}
+
+ [Fact]
+ [PlatformSpecific(TestPlatforms.Windows)] // Uses P/Invokes only suported on windows
+ public unsafe void InvokeCtorWithIsLoadedImageAndPrefetchMetadataOptions2()
+ {
+ using (var tempFile = new TempFile(Path.GetTempFileName()))
+ {
+ File.WriteAllBytes(tempFile.Path, Misc.Members);
+
+ using (SafeLibraryHandle libHandle = global::Interop.Kernel32.LoadLibraryExW(tempFile.Path, IntPtr.Zero, 0))
+ {
+ byte* peImagePtr = (byte*)global::Interop.Kernel32.GetModuleHandle(Path.GetFileName(tempFile.Path));
+
+ Assert.True(peImagePtr != null);
+
+ var peReader = new PEReader(new ReadOnlyUnmanagedMemoryStream(peImagePtr, int.MaxValue), PEStreamOptions.IsLoadedImage | PEStreamOptions.PrefetchMetadata);
+ peReader.Dispose();
+ }
+ }
+ }
}
}