From 497ca33b0b2c008f88294f9b7efe79774e9b58b6 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Mon, 22 May 2023 13:36:27 -0400 Subject: [PATCH] Avoid throwing TypeLoadException for generic 2D arrays (case UUM-34854) Mono was a bit too aggressive with its TypeLoadException processing, not allowing some valid code in this case. This change applies the fix from: https://github.com/dotnet/runtime/pull/85828 --- mono/metadata/class-init.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mono/metadata/class-init.c b/mono/metadata/class-init.c index 88fe3f4e0c98..65f16713adc4 100644 --- a/mono/metadata/class-init.c +++ b/mono/metadata/class-init.c @@ -1124,8 +1124,10 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound mono_class_setup_supertypes (klass); - if (mono_class_is_ginst (eclass)) - mono_class_init_internal (eclass); + // NOTE: this is probably too aggressive if eclass is not a valuetype. It looks like we + // only need the size info in order to set MonoClass:has_references for this array type - + // and for that we only need to setup the fields of the element type if it's not a reference + // type. if (!eclass->size_inited) mono_class_setup_fields (eclass); mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type");