Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 11dea52

Browse files
authored
Add back private BadImageFormatException constructor called by the VM (#11523)
Also removed rethrowing of an exception inside AssemblyName.GetAssemblyName that sometimes resulted into two identical exceptions getting nested into each other. Fixes #11499
1 parent e52d80f commit 11dea52

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
<Compile Include="$(BclSourcesRoot)\System\AppDomainUnloadedException.cs" />
316316
<Compile Include="$(BclSourcesRoot)\System\ArgIterator.cs" />
317317
<Compile Include="$(BclSourcesRoot)\System\Attribute.cs" />
318+
<Compile Include="$(BclSourcesRoot)\System\BadImageFormatException.CoreCLR.cs" />
318319
<Compile Include="$(BclSourcesRoot)\System\BitConverter.cs" />
319320
<Compile Include="$(BclSourcesRoot)\System\Boolean.cs" />
320321
<Compile Include="$(BclSourcesRoot)\System\Buffer.cs" />

src/mscorlib/shared/System/BadImageFormatException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace System
1919
{
2020
[Serializable]
21-
public class BadImageFormatException : SystemException
21+
public partial class BadImageFormatException : SystemException
2222
{
2323
private String _fileName; // The name of the corrupt PE file.
2424
private String _fusionLog; // fusion log (when applicable)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System
6+
{
7+
public partial class BadImageFormatException
8+
{
9+
// Do not delete: this is invoked from native code.
10+
private BadImageFormatException(string fileName, string fusionLog, int hResult)
11+
: base(null)
12+
{
13+
HResult = hResult;
14+
_fileName = fileName;
15+
_fusionLog = fusionLog;
16+
SetMessageField();
17+
}
18+
}
19+
}

src/vm/assemblyname.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,11 @@ FCIMPL1(Object*, AssemblyNameNative::GetFileInformation, StringObject* filenameU
5757
SString sFileName(gc.filename->GetBuffer());
5858
PEImageHolder pImage = PEImage::OpenImage(sFileName, MDInternalImport_NoCache);
5959

60-
EX_TRY
61-
{
62-
// Allow AssemblyLoadContext.GetAssemblyName for native images on CoreCLR
63-
if (pImage->HasNTHeaders() && pImage->HasCorHeader() && pImage->HasNativeHeader())
64-
pImage->VerifyIsNIAssembly();
65-
else
66-
pImage->VerifyIsAssembly();
67-
}
68-
EX_CATCH
69-
{
70-
Exception *ex = GET_EXCEPTION();
71-
EEFileLoadException::Throw(sFileName,ex->GetHR(),ex);
72-
}
73-
EX_END_CATCH_UNREACHABLE;
60+
// Allow AssemblyLoadContext.GetAssemblyName for native images on CoreCLR
61+
if (pImage->HasNTHeaders() && pImage->HasCorHeader() && pImage->HasNativeHeader())
62+
pImage->VerifyIsNIAssembly();
63+
else
64+
pImage->VerifyIsAssembly();
7465

7566
SString sUrl = sFileName;
7667
PEAssembly::PathToUrl(sUrl);

0 commit comments

Comments
 (0)