Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Ropack opened this issue May 11, 2023 · 8 comments
Assignees
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM
Milestone

Comments

@Ropack
Copy link

Ropack commented May 11, 2023

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

@drasticactions
Copy link

This seems like a runtime issue, not something specific to the UI Framework.

@jonathanpeppers What do you think? Should it be transferred?

@jonathanpeppers
Copy link
Member

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.

Yes, this is correct I can move it to dotnet/runtime.

@jonathanpeppers jonathanpeppers transferred this issue from dotnet/maui May 12, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 12, 2023
@ghost
Copy link

ghost commented May 12, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: Ropack
Assignees: -
Labels:

area-System.Reflection

Milestone: -

@jonathanpeppers
Copy link
Member

/cc @steveisok

@steveharter steveharter added area-VM-reflection-mono Reflection issues specific to MonoVM and removed area-System.Reflection labels May 17, 2023
@SamMonoRT SamMonoRT added this to the 8.0.0 milestone May 18, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 18, 2023
@ivanpovazan
Copy link
Member

@Ropack thank you for providing a detailed repro steps.

I have managed to reproduce the issue with: dotnet 7.0.100
However, when I tried it with: dotnet 8.0.100-preview.3.23178.7 the message correctly shows there are 4 properties, meaning that the issue seems to be fixed in the meantime.

Would you mind trying it yourself with .NET8?

I will try to find which PR got it fixed and check if the fix is going to be backported to .NET7.

@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Jun 13, 2023
@Ropack
Copy link
Author

Ropack commented Jun 22, 2023

@ivanpovazan sorry for a late reply. I can confirm that this is fixed in .net8.0, tried with 8.0.100-preview.4.23260.5, thank you for investigating.

@ivanpovazan
Copy link
Member

ivanpovazan commented Jun 22, 2023

No worries and thank you for the confirmation!
The fix will also be backported to .net7, so will keep the issue open until it is fully merged in .net7 branch.

@ivanpovazan
Copy link
Member

Closing as the fix has been backported to .net7 via: #87175

@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM
Projects
None yet
Development

No branches or pull requests

6 participants