From 11dea52f9d82b19481e5a6df54263b85fb5663e2 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 11 May 2017 11:45:38 -0700 Subject: [PATCH] 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 --- src/mscorlib/System.Private.CoreLib.csproj | 1 + src/mscorlib/shared/System/BadImageFormatException.cs | 2 +- .../src/System/BadImageFormatException.CoreCLR.cs | 19 +++++++++++++++++++ src/vm/assemblyname.cpp | 19 +++++-------------- 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 src/mscorlib/src/System/BadImageFormatException.CoreCLR.cs diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 4255499..3373097 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -315,6 +315,7 @@ + diff --git a/src/mscorlib/shared/System/BadImageFormatException.cs b/src/mscorlib/shared/System/BadImageFormatException.cs index eb4c3a6..150330b 100644 --- a/src/mscorlib/shared/System/BadImageFormatException.cs +++ b/src/mscorlib/shared/System/BadImageFormatException.cs @@ -18,7 +18,7 @@ using System.Runtime.Serialization; namespace System { [Serializable] - public class BadImageFormatException : SystemException + public partial class BadImageFormatException : SystemException { private String _fileName; // The name of the corrupt PE file. private String _fusionLog; // fusion log (when applicable) diff --git a/src/mscorlib/src/System/BadImageFormatException.CoreCLR.cs b/src/mscorlib/src/System/BadImageFormatException.CoreCLR.cs new file mode 100644 index 0000000..094668b --- /dev/null +++ b/src/mscorlib/src/System/BadImageFormatException.CoreCLR.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System +{ + public partial class BadImageFormatException + { + // Do not delete: this is invoked from native code. + private BadImageFormatException(string fileName, string fusionLog, int hResult) + : base(null) + { + HResult = hResult; + _fileName = fileName; + _fusionLog = fusionLog; + SetMessageField(); + } + } +} diff --git a/src/vm/assemblyname.cpp b/src/vm/assemblyname.cpp index 90e2a46..6c8367e 100644 --- a/src/vm/assemblyname.cpp +++ b/src/vm/assemblyname.cpp @@ -57,20 +57,11 @@ FCIMPL1(Object*, AssemblyNameNative::GetFileInformation, StringObject* filenameU SString sFileName(gc.filename->GetBuffer()); PEImageHolder pImage = PEImage::OpenImage(sFileName, MDInternalImport_NoCache); - EX_TRY - { - // Allow AssemblyLoadContext.GetAssemblyName for native images on CoreCLR - if (pImage->HasNTHeaders() && pImage->HasCorHeader() && pImage->HasNativeHeader()) - pImage->VerifyIsNIAssembly(); - else - pImage->VerifyIsAssembly(); - } - EX_CATCH - { - Exception *ex = GET_EXCEPTION(); - EEFileLoadException::Throw(sFileName,ex->GetHR(),ex); - } - EX_END_CATCH_UNREACHABLE; + // Allow AssemblyLoadContext.GetAssemblyName for native images on CoreCLR + if (pImage->HasNTHeaders() && pImage->HasCorHeader() && pImage->HasNativeHeader()) + pImage->VerifyIsNIAssembly(); + else + pImage->VerifyIsAssembly(); SString sUrl = sFileName; PEAssembly::PathToUrl(sUrl); -- 2.7.4