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

iOS app crashes when calling GetValue on Virtual Property #26707

Open
MDThomsen opened this issue Dec 18, 2024 · 0 comments
Open

iOS app crashes when calling GetValue on Virtual Property #26707

MDThomsen opened this issue Dec 18, 2024 · 0 comments
Labels
t/bug Something isn't working

Comments

@MDThomsen
Copy link

MDThomsen commented Dec 18, 2024

I am working with a maui app that in some instances relies on getting values through reflection.
There is a specific case where a base class has a virtual property, which is then overridden in a parent class.

In the reproduction project there is a base page with:
public virtual bool IsVisible => true;

and then a page that inherits from that base page, which then overrides the property as such:
public override bool IsVisible => true;

When creating an instance of PropertyInfo on the overriden property with
var visibleBindingPropertyInfo = GetType().GetTypeInfo().GetRuntimeProperty(nameof(IsVisible));

and then calling GetValue by
if (visibleBindingPropertyInfo != null) isVisible = (bool)visibleBindingPropertyInfo.GetValue(this);

causes the iOS app to crash.

The crash occurs when the interpreter is disabled like so;
<MtouchInterpreter>-all</MtouchInterpreter>

If the Interpreter is enabled, then it will not crash. However using the Interpreter is not an option in my case, as it downgrades the performance too much for a production build.

The crash started occurring after updating to VS 2022 with the following workload list:

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
aspire                     8.2.2/8.0.100          VS 17.11.35431.28
maui-windows               8.0.82/8.0.100         VS 17.11.35431.28
maccatalyst                18.0.8303/8.0.100      VS 17.11.35431.28
ios                        18.0.8303/8.0.100      VS 17.11.35431.28
android                    34.0.113/8.0.100       VS 17.11.35431.28

However on the previous installation of visual studio with the following workload list, it is working without crashing:

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
maui-windows               8.0.40/8.0.100         VS 17.10.35013.160
maccatalyst                17.2.8053/8.0.100      VS 17.10.35013.160
ios                        17.2.8053/8.0.100      VS 17.10.35013.160
android                    34.0.95/8.0.100        VS 17.10.35013.160

I also noticed this ticket dotnet/runtime#96611 which mentions something similar, however that is older than the release of 8.0.40 in which it was working.

Steps to Reproduce

  1. Run the reproduction project on a real iOS device (not simulator).
  2. Press the "Click me" button on the main page.
  3. Crash

Link to public reproduction project repository

https://github.com/MDThomsen/BindingCrash.git

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

iOS

Affected platform versions

18.0.8303/8.0.100

Did you find any workaround?

No response

Relevant log output

@MDThomsen MDThomsen added the t/bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant