Skip to content

Commit 209c66f

Browse files
authored
Include file path in BadImageFormatException thrown from AddModule (#126181)
1 parent 98f11ec commit 209c66f

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,23 @@ private EcmaModule AddModule(string filePath, string expectedSimpleName, bool us
194194
filePath = Path.GetFullPath(filePath);
195195
peReader = OpenPEFile(filePath, out mappedViewAccessor);
196196

197+
try
198+
{
199+
// Ensure the PEHeaders can be read
200+
_ = peReader.PEHeaders;
201+
197202
#if !READYTORUN
198-
if (peReader.HasMetadata && (peReader.PEHeaders.CorHeader.Flags & (CorFlags.ILLibrary | CorFlags.ILOnly)) == 0)
199-
throw new NotSupportedException($"Error: C++/CLI is not supported: '{filePath}'");
203+
if (peReader.HasMetadata && (peReader.PEHeaders.CorHeader.Flags & (CorFlags.ILLibrary | CorFlags.ILOnly)) == 0)
204+
throw new NotSupportedException($"Error: C++/CLI is not supported: '{filePath}'");
200205
#endif
201206

202-
pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder())
203-
?? OpenAssociatedSymbolFile(filePath, peReader);
207+
pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder())
208+
?? OpenAssociatedSymbolFile(filePath, peReader);
209+
}
210+
catch (BadImageFormatException ex)
211+
{
212+
throw new BadImageFormatException(ex.Message, filePath);
213+
}
204214
}
205215
else
206216
{

0 commit comments

Comments
 (0)