Skip to content

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

@adityapatwardhan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Reflectionbreaking-changeIssue or PR that represents a breaking API or functional change over a prerelease.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