diff options
author | Gaurav Khanna <gkhanna@microsoft.com> | 2017-04-26 16:53:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-26 16:53:58 -0700 |
commit | 0afaf64d63d27ea5eaa3878b2e638d0c62028195 (patch) | |
tree | 7e10d52e9c7002c13efb7f0b2658ffed10734006 | |
parent | 20aa8b25c8c2d920da3a050728e5ca3156253615 (diff) | |
download | coreclr-0afaf64d63d27ea5eaa3878b2e638d0c62028195.tar.gz coreclr-0afaf64d63d27ea5eaa3878b2e638d0c62028195.tar.bz2 coreclr-0afaf64d63d27ea5eaa3878b2e638d0c62028195.zip |
Fix filename display in exception messages (#11238)
-rw-r--r-- | src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs | 5 | ||||
-rw-r--r-- | src/mscorlib/src/System/__HResults.cs | 1 | ||||
-rw-r--r-- | src/vm/clrex.cpp | 13 | ||||
-rw-r--r-- | src/vm/peimage.cpp | 6 | ||||
-rw-r--r-- | src/vm/peimagelayout.cpp | 13 |
5 files changed, 24 insertions, 14 deletions
diff --git a/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs b/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs index f6415670e3..d4ce9a9ab9 100644 --- a/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs +++ b/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs @@ -27,7 +27,10 @@ namespace System.IO GetFileLoadExceptionMessage(hResult, JitHelpers.GetStringHandleOnStack(ref format)); string message = null; - GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref message)); + if (hResult == System.__HResults.COR_E_BADEXEFORMAT) + message = SR.Arg_BadImageFormatException; + else + GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref message)); return string.Format(CultureInfo.CurrentCulture, format, fileName, message); } diff --git a/src/mscorlib/src/System/__HResults.cs b/src/mscorlib/src/System/__HResults.cs index e4183f637a..0592d814ef 100644 --- a/src/mscorlib/src/System/__HResults.cs +++ b/src/mscorlib/src/System/__HResults.cs @@ -44,6 +44,7 @@ namespace System internal const int COR_E_ARITHMETIC = unchecked((int)0x80070216); internal const int COR_E_ARRAYTYPEMISMATCH = unchecked((int)0x80131503); internal const int COR_E_BADIMAGEFORMAT = unchecked((int)0x8007000B); + internal const int COR_E_BADEXEFORMAT = unchecked((int)0x800700C1); internal const int COR_E_TYPEUNLOADED = unchecked((int)0x80131013); internal const int COR_E_CANNOTUNLOADAPPDOMAIN = unchecked((int)0x80131015); internal const int COR_E_COMEMULATE = unchecked((int)0x80131535); diff --git a/src/vm/clrex.cpp b/src/vm/clrex.cpp index 1c1501e54d..ba040b7e81 100644 --- a/src/vm/clrex.cpp +++ b/src/vm/clrex.cpp @@ -2002,18 +2002,7 @@ void DECLSPEC_NORETURN EEFileLoadException::Throw(LPCWSTR path, HRESULT hr, Exce if (hr == E_OUTOFMEMORY) COMPlusThrowOM(); -#ifndef CROSSGEN_COMPILE - // Remove path - location must be hidden for security purposes - - LPCWSTR pStart = wcsrchr(path, '\\'); - if (pStart != NULL) - pStart++; - else - pStart = path; -#else - LPCWSTR pStart = path; -#endif - EX_THROW_WITH_INNER(EEFileLoadException, (StackSString(pStart), hr), pInnerException); + EX_THROW_WITH_INNER(EEFileLoadException, (StackSString(path), hr), pInnerException); } /* static */ diff --git a/src/vm/peimage.cpp b/src/vm/peimage.cpp index 39b71ff62f..3367ef93c4 100644 --- a/src/vm/peimage.cpp +++ b/src/vm/peimage.cpp @@ -1189,7 +1189,13 @@ HANDLE PEImage::GetFileHandle() } if (m_hFile == INVALID_HANDLE_VALUE) + { +#if !defined(DACCESS_COMPILE) + EEFileLoadException::Throw(m_path, HRESULT_FROM_WIN32(GetLastError())); +#else // defined(DACCESS_COMPILE) ThrowLastError(); +#endif // !defined(DACCESS_COMPILE) + } return m_hFile; } diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 24166817bb..34ba4d8215 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -392,10 +392,21 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) { #ifndef CROSSGEN_COMPILE + // Capture last error as it may get reset below. + + DWORD dwLastError = GetLastError(); // There is no reflection-only load on CoreCLR and so we can always throw an error here. // It is important on Windows Phone. All assemblies that we load must have SEC_IMAGE set // so that the OS can perform signature verification. - ThrowLastError(); + if (pOwner->IsFile()) + { + EEFileLoadException::Throw(pOwner->GetPathForErrorMessages(), HRESULT_FROM_WIN32(dwLastError)); + } + else + { + // Throw generic exception. + ThrowWin32(dwLastError); + } #endif // CROSSGEN_COMPILE |