diff options
author | Steve MacLean <stmaclea@microsoft.com> | 2019-05-08 22:33:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-08 22:33:10 -0400 |
commit | 597e5faa03773e3140850d16381c00a6f9d20335 (patch) | |
tree | 68b82458b0f0774ea8363cfef13aeea513450d8e | |
parent | 93ec324ee831cd4db087ae985c5b3a814ba8abb3 (diff) | |
download | coreclr-597e5faa03773e3140850d16381c00a6f9d20335.tar.gz coreclr-597e5faa03773e3140850d16381c00a6f9d20335.tar.bz2 coreclr-597e5faa03773e3140850d16381c00a6f9d20335.zip |
Remove premature throw (#24450)
* Remove premature throw
ResolveUsingEvent is no longer the last resort for Assembly resolution
and should not be throwing simply because the Assembly.Resolve event did
not find the Assembly
* Delay throw FileNotFound until after AppDomain.AssemblyResolve
-rw-r--r-- | src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs | 9 | ||||
-rw-r--r-- | src/vm/appdomain.cpp | 41 |
2 files changed, 26 insertions, 24 deletions
diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index f14817452e..ba19315ebc 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@ -173,7 +173,7 @@ namespace System.Runtime.Loader return assembly; } - private Assembly ResolveUsingEvent(AssemblyName assemblyName) + private Assembly? ResolveUsingEvent(AssemblyName assemblyName) { string? simpleName = assemblyName.Name; @@ -184,13 +184,6 @@ namespace System.Runtime.Loader assembly = ValidateAssemblyNameWithSimpleName(assembly, simpleName); } - // Since attempt to resolve the assembly via Resolving event is the last option, - // throw an exception if we do not find any assembly. - if (assembly == null) - { - throw new FileNotFoundException(SR.IO_FileLoad, simpleName); - } - return assembly; } diff --git a/src/vm/appdomain.cpp b/src/vm/appdomain.cpp index 9f5749abaa..ed6d05fc87 100644 --- a/src/vm/appdomain.cpp +++ b/src/vm/appdomain.cpp @@ -5328,7 +5328,7 @@ EndTry2:; // Use CoreClr's fusion alternative CoreBindResult bindResult; - pSpec->Bind(this, fThrowOnFileNotFound, &bindResult, FALSE /* fNgenExplicitBind */, FALSE /* fExplicitBindToNativeImage */); + pSpec->Bind(this, FALSE /* fThrowOnFileNotFound */, &bindResult, FALSE /* fNgenExplicitBind */, FALSE /* fExplicitBindToNativeImage */); hrBindResult = bindResult.GetHRBindResult(); if (bindResult.Found()) @@ -5368,8 +5368,6 @@ EndTry2:; } else { - _ASSERTE(fThrowOnFileNotFound == FALSE); - // Don't trigger the resolve event for the CoreLib satellite assembly. A misbehaving resolve event may // return an assembly that does not match, and this can cause recursive resource lookups during error // reporting. The CoreLib satellite assembly is loaded from relative locations based on the culture, see @@ -5382,8 +5380,12 @@ EndTry2:; fForceReThrow = TRUE; // Managed resolve event handler can throw - // Purposly ignore return value - PostBindResolveAssembly(pSpec, &NewSpec, hrBindResult, &pFailedSpec); + BOOL fFailure = PostBindResolveAssembly(pSpec, &NewSpec, hrBindResult, &pFailedSpec); + + if (fFailure && fThrowOnFileNotFound) + { + EEFileLoadException::Throw(pFailedSpec, COR_E_FILENOTFOUND, NULL); + } } } } @@ -6899,20 +6901,27 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB pAssemblyBindingContext = pLoadedPEAssembly->GetHostAssembly(); } -#ifdef FEATURE_COMINTEROP - if (AreSameBinderInstance(pAssemblyBindingContext, GetAppDomain()->GetWinRtBinder())) + if (fResolvedAssembly) { - // It is invalid to return an assembly bound to an incompatible binder - *ppLoadedAssembly = NULL; - SString name; - spec.GetFileOrDisplayName(0, name); - COMPlusThrowHR(COR_E_INVALIDOPERATION, IDS_HOST_ASSEMBLY_RESOLVER_INCOMPATIBLE_BINDING_CONTEXT, name); - } +#ifdef FEATURE_COMINTEROP + if (AreSameBinderInstance(pAssemblyBindingContext, GetAppDomain()->GetWinRtBinder())) + { + // It is invalid to return an assembly bound to an incompatible binder + *ppLoadedAssembly = NULL; + SString name; + spec.GetFileOrDisplayName(0, name); + COMPlusThrowHR(COR_E_INVALIDOPERATION, IDS_HOST_ASSEMBLY_RESOLVER_INCOMPATIBLE_BINDING_CONTEXT, name); + } #endif // FEATURE_COMINTEROP - // Get the ICLRPrivAssembly reference to return back to. - *ppLoadedAssembly = clr::SafeAddRef(pAssemblyBindingContext); - hr = S_OK; + // Get the ICLRPrivAssembly reference to return back to. + *ppLoadedAssembly = clr::SafeAddRef(pAssemblyBindingContext); + hr = S_OK; + } + else + { + hr = COR_E_FILENOTFOUND; + } } GCPROTECT_END(); |