From 9197fa7a645c9c407213bcb56a0bad69a91ba955 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 28 Jun 2021 13:05:20 +0200 Subject: [PATCH] [mono] Fix loader incompatibility w.r.t. Resolving event * When loading a non-satellite assembly into a non-default ALC, invoke the Resolving event in the default ALC first. * Fixes https://github.com/dotnet/runtime/issues/54814 --- src/mono/mono/metadata/assembly.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index e98264a2f939da..8a52e63bc856d6 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -1061,7 +1061,8 @@ netcore_load_reference (MonoAssemblyName *aname, MonoAssemblyLoadContext *alc, M * * 7. If this is a satellite request, call the ALC ResolveSatelliteAssembly method. * - * 8. Call the ALC Resolving event. + * 8. Call the ALC Resolving event. If the ALC is not the default and this is not + * a satellite request, call the Resolving event in the default ALC first. * * 9. Call the ALC AssemblyResolve event (except for corlib satellite assemblies). * @@ -1138,6 +1139,15 @@ netcore_load_reference (MonoAssemblyName *aname, MonoAssemblyLoadContext *alc, M } } + // For compatibility with CoreCLR, invoke the Resolving event in the default ALC first whenever loading + // a non-satellite assembly into a non-default ALC. See: https://github.com/dotnet/runtime/issues/54814 + if (!is_default && !is_satellite) { + reference = mono_alc_invoke_resolve_using_resolving_event_nofail (mono_alc_get_default (), aname); + if (reference) { + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Assembly found with the Resolving event (default ALC): '%s'.", aname->name); + goto leave; + } + } reference = mono_alc_invoke_resolve_using_resolving_event_nofail (alc, aname); if (reference) { mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Assembly found with the Resolving event: '%s'.", aname->name);