Skip to content

[Android] Inherited internal properties are not returned via reflection #76881

@steveisok

Description

@steveisok

Description

Issue started from dotnet/android#7445

Type.GetRuntimeProperties(), Type.GetProperties(..), etc. don't return internal properties that are defined in a base class of the given type when running on net6.0-android. When I run the same code as a net6.0 console application or a Xamarin.Android app, the properties are correctly returned.

Reproduction Steps

  1. Create a new .NET 6 Android application. Add the code below and run the Test.Execute method.
    public static class Test
    {
        public static void Execute()
        {
            var obj = new Class2();
            var properties = obj.GetType().GetRuntimeProperties();

            var names = properties.Select(x => x.Name).ToList();
            Console.WriteLine($"Found {names.Count} properties: {string.Join(", ", names)}");

            // Xamarin.Android: Found 2 properties: TestProp2, TestProp1
            // net6.0:          Found 2 properties: TestProp2, TestProp1
            // net6.0-android:  Found 1 properties: TestProp2
        }
    }

    public class Class1
    {
        internal int TestProp1 { get; set; }
    }

    public class Class2 : Class1
    {
        internal int TestProp2 { get; set; }
    }

Expected behavior

The sample should produce Found 2 properties: TestProp2, TestProp1 as output

Actual behavior

The output produces Found 1 properties: TestProp2

Regression?

In terms of migrating from xamarin-android to .net android, yes.

Known Workarounds

No response

Configuration

net6-android, VS 2022 17.3.5

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions