Log path in a particular BIFE (dotnet/coreclr#27469)
authorDan Moseley <danmose@microsoft.com>
Mon, 28 Oct 2019 03:26:10 +0000 (20:26 -0700)
committerJan Kotas <jkotas@microsoft.com>
Mon, 28 Oct 2019 03:26:10 +0000 (20:26 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/68e07f1fd68aa1aa568c6de571c44a388d3710bd

src/coreclr/src/vm/assemblynative.cpp
src/coreclr/src/vm/excep.cpp

index c3711c3..d0018e4 100644 (file)
@@ -252,13 +252,13 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext
         
         // Need to verify that this is a valid CLR assembly. 
         if (!pILImage->CheckILFormat())
-            ThrowHR(COR_E_BADIMAGEFORMAT, BFA_BAD_IL);
+            THROW_BAD_FORMAT(BFA_BAD_IL, pILImage.GetValue());
 
         LoaderAllocator* pLoaderAllocator = NULL;
         if (SUCCEEDED(pBinderContext->GetLoaderAllocator((LPVOID*)&pLoaderAllocator)) && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly())
         {
             // Loading IJW assemblies into a collectible AssemblyLoadContext is not allowed
-            ThrowHR(COR_E_BADIMAGEFORMAT, BFA_IJW_IN_COLLECTIBLE_ALC);
+            THROW_BAD_FORMAT(BFA_IJW_IN_COLLECTIBLE_ALC, pILImage.GetValue());
         }
     }
     
@@ -272,7 +272,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext
         {
             // ReadyToRun images are treated as IL images by the rest of the system
             if (!pNIImage->CheckILFormat())
-                ThrowHR(COR_E_BADIMAGEFORMAT);
+                THROW_BAD_FORMAT(COR_E_BADIMAGEFORMAT, pNIImage.GetValue());
 
             pILImage = pNIImage.Extract();
             pNIImage = NULL;
@@ -280,7 +280,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext
         else
         {
             if (!pNIImage->CheckNativeFormat())
-                ThrowHR(COR_E_BADIMAGEFORMAT);
+                THROW_BAD_FORMAT(COR_E_BADIMAGEFORMAT, pNIImage.GetValue());
         }
     }
 #endif // FEATURE_PREJIT
index 92b645e..bc78279 100644 (file)
@@ -12327,20 +12327,25 @@ VOID ThrowBadFormatWorker(UINT resID, LPCWSTR imageName DEBUGARG(__in_z const ch
 #ifndef DACCESS_COMPILE
     SString msgStr;
 
-    if ((imageName != NULL) && (imageName[0] != 0))
-    {
-        msgStr += W("[");
-        msgStr += imageName;
-        msgStr += W("] ");
-    }
-
     SString resStr;
     if (resID == 0 || !resStr.LoadResource(CCompRC::Optional, resID))
     {
-        resStr.LoadResource(CCompRC::Error, MSG_FOR_URT_HR(COR_E_BADIMAGEFORMAT));
+        resStr.LoadResource(CCompRC::Error, BFA_BAD_IL); // "Bad IL format."
     }
     msgStr += resStr;
 
+    if ((imageName != NULL) && (imageName[0] != 0))
+    {
+        SString suffixResStr;
+        if (suffixResStr.LoadResource(CCompRC::Optional, COR_E_BADIMAGEFORMAT)) // "The format of the file '%1' is invalid."
+        {
+            SString suffixMsgStr;
+            suffixMsgStr.FormatMessage(FORMAT_MESSAGE_FROM_STRING, (LPCWSTR)suffixResStr, 0, 0, imageName);
+            msgStr.AppendASCII(" ");
+            msgStr += suffixMsgStr;
+        }
+    }
+
 #ifdef _DEBUG
     if (0 != strcmp(cond, "FALSE"))
     {