Skip to content

Issues with reflection where the return type of GetMember is an empty array of MemberInfo #98533

Description

@adityapatwardhan

Description

When trying to get the IsInterface member System.Runtimetype we get back an empty array of MemberInfo.
Expected to have 1 item in the array

Reproduction Steps

Project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

Program.cs:

using System.IO;

var t = typeof(Path).Assembly.GetType("System.IO.Path");
Console.WriteLine($"Value == {t?.IsInterface}");

Console.WriteLine($"{t?.GetType()}");
var member =  t?.GetType().GetMember("IsInterface");

if (member is not null)
{
    Console.WriteLine($"{member.GetType()}");
    Console.WriteLine($"{member.Length}");
}

Expected behavior

Value == False
System.RuntimeType
System.Reflection.MemberInfo[]
1

Actual behavior

Value == False
System.RuntimeType
System.Reflection.MemberInfo[]
0

Regression?

This is a regression from .NET 8

Known Workarounds

None

Configuration

.NET 9 Preview 1
Failures happen on Windows, Linux and Mac

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Reflectionbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.needs-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions