From ed7d2fb13b555ede610daa86f181fa21e49e8dfc Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Wed, 13 Jan 2021 17:27:13 +0100 Subject: [PATCH] Don't assume presence of MonoResolveUnmanagedDllUsingEvent method (#46917) Follow up change missing in #46323 Fixes #46908 --- src/mono/mono/metadata/native-library.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index fb92e616ef3f7..2753582d00ae6 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -699,13 +699,18 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly MONO_STATIC_POINTER_INIT (MonoMethod, resolve) ERROR_DECL (local_error); - MonoClass *alc_class = mono_class_get_assembly_load_context_class (); - g_assert (alc_class); - resolve = mono_class_get_method_from_name_checked (alc_class, "MonoResolveUnmanagedDllUsingEvent", -1, 0, local_error); - mono_error_assert_ok (local_error); + static gboolean inited; + if (!inited) { + MonoClass *alc_class = mono_class_get_assembly_load_context_class (); + g_assert (alc_class); + resolve = mono_class_get_method_from_name_checked (alc_class, "MonoResolveUnmanagedDllUsingEvent", -1, 0, local_error); + inited = TRUE; + } + mono_error_cleanup (local_error); MONO_STATIC_POINTER_INIT_END (MonoMethod, resolve) - g_assert (resolve); + if (!resolve) + return NULL; if (mono_runtime_get_no_exec ()) return NULL;