diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index a04dd075a8f6..f8e08f5913d4 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -9837,6 +9837,11 @@ get_virtual_stelemref_kind (MonoClass *element_class) return STELEMREF_OBJECT; if (is_monomorphic_array (element_class)) return STELEMREF_SEALED_CLASS; + + /* magic ifaces requires aditional checks for when the element type is an array */ + if (MONO_CLASS_IS_INTERFACE (element_class) && element_class->is_array_special_interface) + return STELEMREF_COMPLEX; + /* Compressed interface bitmaps require code that is quite complex, so don't optimize for it. */ if (MONO_CLASS_IS_INTERFACE (element_class) && !mono_class_has_variant_generic_params (element_class)) #ifdef COMPRESSED_INTERFACE_BITMAP diff --git a/mono/mini/objects.cs b/mono/mini/objects.cs index 97ca3c180115..b6e1246fc74a 100644 --- a/mono/mini/objects.cs +++ b/mono/mini/objects.cs @@ -1,6 +1,7 @@ using System; using System.Text; using System.Reflection; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -1829,6 +1830,30 @@ public static int test_0_typedref () { return 0; } + + public interface IFoo + { + int MyInt { get; } + } + + public class IFooImpl : IFoo + { + public int MyInt => 0; + } + + //gh 6266 + public static int test_0_store_to_magic_iface_array () + { + ICollection arr1 = new IFooImpl[1] { new IFooImpl() }; + ICollection arr2 = new IFooImpl[1] { new IFooImpl() }; + + ICollection[] a2d = new ICollection[2] { + arr1, + arr2, + }; + + return 0; + } } #if __MOBILE__