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 #110995

Open
MDThomsen opened this issue Dec 18, 2024 · 11 comments · Fixed by #111310
Open

iOS app crashes when calling GetValue on Virtual Property #110995

MDThomsen opened this issue Dec 18, 2024 · 11 comments · Fixed by #111310
Assignees
Labels
area-Codegen-Interpreter-mono in-pr There is an active PR which will close this issue when it is merged os-ios Apple iOS untriaged New issue has not been triaged by the area owner
Milestone

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 #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

@PureWeen
Copy link
Member

This issue was moved to xamarin/xamarin-macios#21845

@rolfbjarne
Copy link
Member

With the following changes to the test repo:

diff --git a/BindingCrash.iOS/BindingCrash.iOS.csproj b/BindingCrash.iOS/BindingCrash.iOS.csproj
index 1b4b608..f325a78 100644
--- a/BindingCrash.iOS/BindingCrash.iOS.csproj
+++ b/BindingCrash.iOS/BindingCrash.iOS.csproj
@@ -1,8 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk">

        <PropertyGroup>
-               <TargetFramework>net8.0-ios</TargetFramework>
-               <SupportedOSPlatformVersion>11.0</SupportedOSPlatformVersion>
+               <TargetFramework>net9.0-ios</TargetFramework>^M
+               <SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion>^M
                <OutputType>Exe</OutputType>
                <Nullable>enable</Nullable>
                <ImplicitUsings>enable</ImplicitUsings>
@@ -30,7 +30,7 @@
                <UseNativeHttpHandler>True</UseNativeHttpHandler>
                <MtouchFloat32>False</MtouchFloat32>
                <MtouchI18n>west</MtouchI18n>
-               <MtouchNoSymbolStrip>False</MtouchNoSymbolStrip>
+               <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>^M
                <MtouchExtraArgs>--force-thread-check --optimize=force-rejected-types-removal --warn-on-type-ref=UIKit.UIWebView -warnaserror:1503</MtouchExtraArgs>
                <MtouchInterpreter>-all</MtouchInterpreter>
        </PropertyGroup>
diff --git a/BindingCrash.iOS/Info.plist b/BindingCrash.iOS/Info.plist
index c775d76..ffb20b8 100644
--- a/BindingCrash.iOS/Info.plist
+++ b/BindingCrash.iOS/Info.plist
@@ -5,7 +5,7 @@
     <key>CFBundleDisplayName</key>
     <string>BindingCrash</string>
     <key>CFBundleIdentifier</key>
-    <string></string>
+    <string>BindingCrash</string>^M
     <key>CFBundleShortVersionString</key>
     <string>1.0</string>
     <key>CFBundleVersion</key>

then building and running like this:

dotnet run --project BindingCrash.iOS/BindingCrash.iOS.csproj /p:RuntimeIdentifier=ios-arm64

I get this stack trace from the crash:

=================================================================
	Native stacktrace:
=================================================================
	0x106613358 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : mono_dump_native_crash_info
	0x1065fe444 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : mono_handle_native_crash
	0x1065e0bc8 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : mono_sigsegv_signal_handler_debug
	0x2223e5c10 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x10661f5c8 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : mono_interp_exec_method
	0x106614188 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : interp_entry_from_trampoline
	0x10618caf8 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : wrapper_other_object___interp_lmf_mono_interp_entry_from_trampoline_intptr_intptr
	0x1061c2788 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : native_to_interp_trampoline
	0x1061bdf1c - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : gsharedvt_out_trampoline
	0x1061270a8 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : System_Reflection_RuntimePropertyInfo_GetterAdapterFrame_T_GSHAREDVT_R_GSHAREDVT_System_Reflection_RuntimePropertyInfo_Getter_2_T_GSHAREDVT_R_GSHAREDVT_object
	0x105f72184 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : System_Reflection_RuntimePropertyInfo_GetValue_object_object__
	0x105f7e9e4 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : System_Reflection_PropertyInfo_GetValue_object
	0x1059b8484 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : BindingCrash_CrashingPage__ctor
	0x1059b85b0 - /private/var/containers/Bundle/Application/CCA20F5C-92DC-48C6-BD15-5F1300DBE487/BindingCrash.iOS.app/BindingCrash.iOS : BindingCrash_MainPage_OnCounterClicked_object_System_EventArgs
[...]

Which looks like an issue with the interpreter.

@dotnet dotnet unlocked this conversation Dec 30, 2024
@rolfbjarne rolfbjarne reopened this Dec 30, 2024
@rolfbjarne rolfbjarne transferred this issue from dotnet/maui Dec 30, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 30, 2024
@jeffschwMSFT jeffschwMSFT added os-ios Apple iOS area-VM-reflection-mono Reflection issues specific to MonoVM labels Jan 6, 2025
@vitek-karas vitek-karas added area-Codegen-Interpreter-mono and removed area-VM-reflection-mono Reflection issues specific to MonoVM labels Jan 6, 2025
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 6, 2025
@vitek-karas
Copy link
Member

@BrzVlad could you please take a look?

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Jan 11, 2025
@MDThomsen
Copy link
Author

@vitek-karas Hi, I am wondering whether this would be something that would be included in a 8.0.X service release?

@vitek-karas
Copy link
Member

@MDThomsen - we'll look into backporting this once we have the fix merged into main (.NET 10).

@MDThomsen
Copy link
Author

@vitek-karas That's great to hear as this has quite big implications for what I'm developing.

@vitek-karas
Copy link
Member

@MDThomsen - no promises - the fix is relatively large and thus risky :-) Also our first target will be .NET 9.

@MDThomsen
Copy link
Author

@vitek-karas Of course, I completely understand that based on the changes in the PR. I just want to stress that this is quite a breaking bug, and at the moment bumping to .net9 is not an option for the product my team is developing, due to stability issues on .net 9.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jan 15, 2025
@vitek-karas
Copy link
Member

@BrzVlad please try to backport this to both 9 and 8 - we'll see if it meets the bar.

@vitek-karas vitek-karas reopened this Jan 15, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 15, 2025
@vitek-karas
Copy link
Member

Reopening as the issues was filed against .NET 8 - we will consider backporting this into 9 and 8.

@vitek-karas vitek-karas added this to the 8.0.x milestone Jan 15, 2025
@shnaz
Copy link

shnaz commented Jan 15, 2025

@vitek-karas Thank you very much!
I have same issue and it would be very appreciated if we are not forced to .NET 9, just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Codegen-Interpreter-mono in-pr There is an active PR which will close this issue when it is merged os-ios Apple iOS untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants