Skip to content

ArrayTypeMismatchException when using array of generic ICollection<T> or IList<T> #1120

@MaasOne

Description

@MaasOne

Steps to Reproduce

  1. Use the following test interface and class
public interface IFoo
{
    int MyInt { get; }
}

public class Bar : IFoo
{
    public int MyInt => 0;
}
  1. Use the following test code for reproducing the exception
ICollection<IFoo> arr1 = new Bar[1] { new Bar() };
ICollection<IFoo> arr2 = new Bar[1] { new Bar() };

ICollection<IFoo>[] a2d = new ICollection<IFoo>[2] { arr1, arr2 }; //ArrayTypeMismatchException
  1. Try the same test code with IList<T>
IList<IFoo> arr1 = new Bar[1] { new Bar() };
IList<IFoo> arr2 = new Bar[1] { new Bar() };

IList<IFoo>[] a2d = new IList<IFoo>[2] { arr1, arr2 }; //ArrayTypeMismatchException

Expected Behavior

Expected no exception throwing.

Actual Behavior

Throws an ArrayTypeMismatchException at last line of test code at runtime when using ICollection<T> or IList<T>.
The following types are working properly as expected:
IEnumerable
IEnumerable<T>
ICollection
IList
Code is compiling successfully with all types.

Version Information

Visual Studio: 15.5.2
Mono: MonoAndroid70 / 4.0.30319 / 8.1.0.25
Android: 7.0
Kernel: 4.1.18-gdd36b34

Log File

at (wrapper stelemref) System.Object:virt_stelemref_interface (intptr,object)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions