diff --git a/src/mono/mono/metadata/assembly-load-context.c b/src/mono/mono/metadata/assembly-load-context.c index 93686653fb098..627086e3f5dfd 100644 --- a/src/mono/mono/metadata/assembly-load-context.c +++ b/src/mono/mono/metadata/assembly-load-context.c @@ -424,11 +424,19 @@ mono_alc_from_gchandle (MonoGCHandle alc_gchandle) if (alc_gchandle == default_alc->gchandle) return default_alc; - HANDLE_FUNCTION_ENTER (); - MonoManagedAssemblyLoadContextHandle managed_alc = MONO_HANDLE_CAST (MonoManagedAssemblyLoadContext, mono_gchandle_get_target_handle (alc_gchandle)); - g_assert (!MONO_HANDLE_IS_NULL (managed_alc)); - MonoAssemblyLoadContext *alc = MONO_HANDLE_GETVAL (managed_alc, native_assembly_load_context); - HANDLE_FUNCTION_RETURN_VAL (alc); + MONO_STATIC_POINTER_INIT (MonoClassField, resolve) + + MonoClass *alc_class = mono_class_get_assembly_load_context_class (); + g_assert (alc_class); + resolve = mono_class_get_field_from_name_full (alc_class, "_nativeAssemblyLoadContext", NULL); + + MONO_STATIC_POINTER_INIT_END (MonoClassField, resolve) + + g_assert (resolve); + + MonoAssemblyLoadContext *alc = NULL; + mono_field_get_value_internal (mono_gchandle_get_target_internal (alc_gchandle), resolve, &alc); + return alc; } MonoGCHandle diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 4a47bd81ddfb6..425604aeabdbd 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -1406,13 +1406,6 @@ typedef enum { UNLOADING = 1 } MonoManagedAssemblyLoadContextInternalState; -// Keep in sync with System.Runtime.Loader.AssemblyLoadContext -typedef struct { - MonoObject object; - MonoAssemblyLoadContext *native_assembly_load_context; -} MonoManagedAssemblyLoadContext; - -TYPED_HANDLE_DECL (MonoManagedAssemblyLoadContext); /* All MonoInternalThread instances should be pinned, so it's safe to use the raw ptr. However * for uniformity, icall wrapping will make handles anyway. So this is the method for getting the payload.