From 4cfe89f616c95d92005fd24982a62de8e0db37f0 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 18 Nov 2020 16:41:44 -0500 Subject: [PATCH] Run class cctor in RuntimeHelpers.GetUninitializedObject(type). Fixes https://github.com/dotnet/runtime/issues/44852. --- src/mono/mono/metadata/icall.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index d54276ceadc1e7..2dd46350818779 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -1372,6 +1372,7 @@ MonoObjectHandle ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetUninitializedObjectInternal (MonoType *handle, MonoError *error) { MonoClass *klass; + MonoVTable *vtable; g_assert (handle); @@ -1401,6 +1402,12 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetUninitializedObjectI return NULL_HANDLE; } + vtable = mono_class_vtable_checked (mono_domain_get (), klass, error); + return_val_if_nok (error, NULL_HANDLE); + + mono_runtime_class_init_full (vtable, error); + return_val_if_nok (error, NULL_HANDLE); + if (m_class_is_nullable (klass)) return mono_object_new_handle (mono_domain_get (), m_class_get_nullable_elem_class (klass), error); else