-
Couldn't load subscription status.
- Fork 5.2k
Description
Description
System.RuntimeType no longer seems to define the IsInterface property when inspecting via reflection. I'm not sure if this is a change in System.RuntimeType, but using the BindingFlags.FlattenHierarchy ought to return it for all subclasses of Type.
So, I propose the underlying issue is that GetProperties GetProperty or BindingFlags.FlattenHierarchy no longer work as expected in .NET 9.
MATLAB relies on the existing behavior, so this is another way that .NET 9 has broken integration with MATLAB.
Reproduction Steps
using System;
using System.Linq;
using System.Reflection;
Console.WriteLine(Environment.Version);
var runtimeType = System.Type.GetType("System.RuntimeType");
Console.WriteLine(runtimeType);
// This used to work
var props = runtimeType.GetProperties();
var isInterfaceProp = props.FirstOrDefault(p => p.Name == "IsInterface");
Console.WriteLine(isInterfaceProp);
// This used to work
isInterfaceProp = runtimeType.GetProperty("IsInterface");
Console.WriteLine(isInterfaceProp);
// This used to work
isInterfaceProp = runtimeType.GetProperty("IsInterface", BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
Console.WriteLine(isInterfaceProp);Observe in .NET 8 and lower, this returns the "IsInterface" property. In .NET 9, IsInterface is not found. I have only tested this on Windows.
Expected behavior
IsInterface is a public instance property of all subclasses of System.Type, especially when using BindingFlags.FlattenHierarchy.
Actual behavior
IsInterface is only returned when inspecting non-public properties. Which doesn't make sense, because IsInterface is a public property of System.Type.
Regression?
Yes. This worked as expected in .NET 8 and lower, including .NET Framework.
Known Workarounds
No response
Configuration
Environment.Version == 9.0.8
dotnet --version == 9.0.304
Other information
No response