未验证 提交 7d7b0fa3 编写于 作者: E Elinor Fung 提交者: GitHub

Add error message for loading assembly with incompatible architecture (#91289)

- Add an error message explicitly calling out incompatible architecture when we detect that case
- Propagate the load error when failing to load a PE image
- Show file path if trying to load from a path, assembly display name otherwise
上级 1c7adc65
......@@ -217,7 +217,13 @@ namespace BinderTracing
// Use the error message that would be reported in the file load exception
StackSString errorMsg;
if (mvidMismatch)
errorMsg.LoadResource(CCompRC::Error, IDS_HOST_ASSEMBLY_RESOLVER_ASSEMBLY_ALREADY_LOADED_IN_CONTEXT);
{
StackSString format;
format.LoadResource(CCompRC::Error, IDS_EE_FILELOAD_ERROR_GENERIC);
StackSString details;
details.LoadResource(CCompRC::Error, IDS_HOST_ASSEMBLY_RESOLVER_ASSEMBLY_ALREADY_LOADED_IN_CONTEXT);
errorMsg.FormatMessage(FORMAT_MESSAGE_FROM_STRING, format.GetUnicode(), 0, 0, m_assemblyName, details);
}
const BindResult::AttemptResult *inContextAttempt = bindResult.GetAttempt(true /*foundInContext*/);
const BindResult::AttemptResult *appAssembliesAttempt = bindResult.GetAttempt(false /*foundInContext*/);
......
......@@ -119,7 +119,7 @@ HRESULT CustomAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage,
// Validate architecture
if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture()))
{
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
IF_FAIL_GO(CLR_E_BIND_ARCHITECTURE_MISMATCH);
}
// Disallow attempt to bind to the core library. Aside from that,
......
......@@ -128,7 +128,7 @@ HRESULT DefaultAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage,
// Validate architecture
if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture()))
{
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
IF_FAIL_GO(CLR_E_BIND_ARCHITECTURE_MISMATCH);
}
// Easy out for CoreLib
......
......@@ -2103,6 +2103,12 @@
<Comment>Returned by binders that bind based on type identity.</Comment>
</HRESULT>
<HRESULT NumericValue="0x80132006">
<SymbolicName>CLR_E_BIND_ARCHITECTURE_MISMATCH</SymbolicName>
<Message>"The assembly architecture is not compatible with the current process architecture."</Message>
<Comment>Indicates the assembly cannot be loaded because its architecture is not compatible with that of the current process.</Comment>
</HRESULT>
<HRESULT NumericValue="0x80132009">
<SymbolicName>CLR_E_GC_OOM</SymbolicName>
<Message>"Failfast due to an OOM during a GC"</Message>
......
......@@ -297,6 +297,7 @@ BEGIN
MSG_FOR_URT_HR(CLR_E_BIND_UNRECOGNIZED_IDENTITY_FORMAT) "The provided identity format is not recognized."
MSG_FOR_URT_HR(CLR_E_BIND_ASSEMBLY_NOT_FOUND) "A binding for the specified assembly name was not found."
MSG_FOR_URT_HR(CLR_E_BIND_TYPE_NOT_FOUND) "A binding for the specified type name was not found."
MSG_FOR_URT_HR(CLR_E_BIND_ARCHITECTURE_MISMATCH) "The assembly architecture is not compatible with the current process architecture."
MSG_FOR_URT_HR(CLR_E_GC_OOM) "Failfast due to an OOM during a GC"
MSG_FOR_URT_HR(CLR_E_GC_BAD_AFFINITY_CONFIG) "GCHeapAffinitizeMask or GCHeapAffinitizeRanges didn't specify any CPUs the current process is affinitized to."
MSG_FOR_URT_HR(CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT) "GCHeapAffinitizeRanges configuration string has invalid format."
......
......@@ -369,6 +369,7 @@
#define CLR_E_BIND_UNRECOGNIZED_IDENTITY_FORMAT EMAKEHR(0x2003)
#define CLR_E_BIND_ASSEMBLY_NOT_FOUND EMAKEHR(0x2004)
#define CLR_E_BIND_TYPE_NOT_FOUND EMAKEHR(0x2005)
#define CLR_E_BIND_ARCHITECTURE_MISMATCH EMAKEHR(0x2006)
#define CLR_E_GC_OOM EMAKEHR(0x2009)
#define CLR_E_GC_BAD_AFFINITY_CONFIG EMAKEHR(0x200a)
#define CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT EMAKEHR(0x200b)
......
......@@ -137,8 +137,6 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pIma
Assembly *pLoadedAssembly = NULL;
ReleaseHolder<BINDER_SPACE::Assembly> pAssembly;
DWORD dwMessageID = IDS_EE_FILELOAD_ERROR_GENERIC;
// Set the caller's assembly to be CoreLib
DomainAssembly *pCallersAssembly = SystemDomain::System()->SystemAssembly()->GetDomainAssembly();
......@@ -155,15 +153,22 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pIma
if (hr != S_OK)
{
// Give a more specific message for the case when we found the assembly with the same name already loaded.
StackSString name;
spec.GetDisplayName(0, name);
if (hr == COR_E_FILELOAD)
{
dwMessageID = IDS_HOST_ASSEMBLY_RESOLVER_ASSEMBLY_ALREADY_LOADED_IN_CONTEXT;
// Give a more specific message for the case when we found the assembly with the same name already loaded.
// Show the assembly name, since we know the error is about the assembly name.
StackSString errorString;
errorString.LoadResource(CCompRC::Error, IDS_HOST_ASSEMBLY_RESOLVER_ASSEMBLY_ALREADY_LOADED_IN_CONTEXT);
COMPlusThrow(kFileLoadException, IDS_EE_FILELOAD_ERROR_GENERIC, name, errorString);
}
else
{
// Propagate the actual HResult to the FileLoadException
// Use the path if this load request was for a file path, display name otherwise
EEFileLoadException::Throw(pImage->GetPath().IsEmpty() ? name : pImage->GetPath(), hr);
}
StackSString name;
spec.GetDisplayName(0, name);
COMPlusThrowHR(COR_E_FILELOAD, dwMessageID, name);
}
PEAssemblyHolder pPEAssembly(PEAssembly::Open(pAssembly->GetPEImage(), pAssembly));
......
......@@ -641,7 +641,6 @@ public static BindOperation LoadFromAssemblyPath_FoundInLoadContext_DifferentMvi
Cached = false,
ResolutionAttempts = new List<ResolutionAttempt>()
{
// GetResolutionAttempt(assemblyName, ResolutionStage.FindInLoadContext, AssemblyLoadContext.Default, ResolutionResult.IncompatibleVersion, UseDependentAssembly()),
GetResolutionAttempt(assemblyName, ResolutionStage.FindInLoadContext, AssemblyLoadContext.Default, ResolutionResult.Failure, new AssemblyName($"{DependentAssemblyName}, Version=1.0.0.0"), Helpers.GetAssemblyInAppPath(DependentAssemblyName), errorMessage),
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册