Skip to content

Type.GetProperties does not return non-public properties from inherited type on Android #86149

@Ropack

Description

@Ropack

Description

This may be bug of some underlying framework/runtime, possibly Mono. If this is not appropriate repo to file this issue in, please direct me to correct one.

During upgrade from Xamarin.Forms to MAUI we discovered odd bug. Reflection after upgrade is not behaving the same as before. When getting all properties for a type, including the non-public ones, the protected properties declared in inherited type are not returned.

As described in the repro steps as well as in linked repro project, when declaring type Foo, that inherits from type Bar, the properties returned by GetProperties method does not include non-public properties declared in Bar even though the BindingFlags specify that they should.

Issue is experienced only in Android, when the same app is run in Windows, it returns expected results.

Steps to Reproduce

  1. Create new MAUI App
  2. Create two types with public and private properties, one inherited from another
public class Foo : Bar
{
    public string PublicFromFoo { get; set; }
    private string PrivateFromFoo { get; set; }
}

public class Bar
{
    public string PublicFromBar { get; set; }
    protected string ProtectedFromBar { get; set; }
}
  1. In MainPage add code, that should get all properties from type Foo
    var properties = typeof(Foo).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); `

Expected result: properties is array with Length 4
Actual result: properties is array with Length 3

Link to public reproduction project repository

https://github.com/Ropack/MauiReflectionBugRepro

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions