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);
}
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);
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 */
}
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;
}
{
#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