diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DynamicallyAccessedMembersBinder.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DynamicallyAccessedMembersBinder.cs index 6c49b0c3f2d8..01b819df2e13 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DynamicallyAccessedMembersBinder.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DynamicallyAccessedMembersBinder.cs @@ -294,7 +294,14 @@ public static IEnumerable GetEventsOnTypeHierarchy(this TypeDes bool onBaseType = false; while (type != null) { - var ecmaType = (EcmaType)type.GetTypeDefinition(); + if (type.GetTypeDefinition() is not EcmaType ecmaType) + { + // Go down the inheritance chain to see if we have an EcmaType later. + // Arrays would hit this (base type of arrays is the EcmaType for System.Array). + type = type.BaseType; + onBaseType = true; + continue; + } foreach (var eventHandle in ecmaType.MetadataReader.GetTypeDefinition(ecmaType.Handle).GetEvents()) {