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

System.InvalidCastException when using a custom map handler on iOS and .NET 9. #26000

Open
kaniosm opened this issue Nov 20, 2024 · 4 comments
Open
Labels
area-controls-map Map / Maps platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@kaniosm
Copy link

kaniosm commented Nov 20, 2024

Description

After updating to .NET 9 (MAUI 9.0.10) whenever opening my customized map control while the app is still looking for the GPS location the app crashes with the below error:
NativeHandle Registrar_Callbacks.callback_1320_MapKit_MKMapView__MKMapViewDelegate_GetViewForAnnotation(IntPtr pobj, IntPtr sel, IntPtr p0, IntPtr p1, IntPtr* exception_gchandle).
The same was not happening in .NET 8.
This is happening only in release mode.

Steps to Reproduce

  1. Create a new .NET 9 MAUI project.
  2. Create a custom map hander with a handler to the GetViewForAnnotation.
  3. Opt-out from automatic handler disconnect since this will crash the app after opening the map page for a second time. (see Disconnecting Map Handler causes Map to crash on second page entrance and moving to region. #20612).
  4. Deploy the release build to a physical device.
  5. Request the user location
  6. Immediately open the map page

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@kaniosm kaniosm added the t/bug Something isn't working label Nov 20, 2024
@samhouts samhouts added platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending labels Nov 20, 2024
@kevinxufei
Copy link

Could you provide us with a sample project so we can investigate it further? Looking forward to your reply!

@eerojaaskelainen
Copy link

Might be relative to #25762.

@kaniosm
Copy link
Author

kaniosm commented Nov 21, 2024

Thanks @eerojaaskelainen,
It seems that the issue is indeed the same, but it's not happening all times.
In my case I noticed that it always happens whenever I open the map while the user location is still running, but I faced the same under different conditions that are more difficult to replicate.

I'll try to to reproduce this in a clear project and post here.
As commented on the other post, I believe it has to do with the cast of the user location to IMKAnnotation by looking at this from the original source.

// https://bugzilla.xamarin.com/show_bug.cgi?id=26416
var userLocationAnnotation = Runtime.GetNSObject(annotation.Handle) as MKUserLocation;

@kaniosm
Copy link
Author

kaniosm commented Nov 21, 2024

Could you provide us with a sample project so we can investigate it further? Looking forward to your reply!

Sample project below.
In this project the issue is reproducible only in release.

MauiMapTest.zip

Surprisingly, I just realised that the same issue exists with Maps even when not using the custom handler, and you set the IsShowingUser="True"

@PureWeen PureWeen added the area-controls-map Map / Maps label Nov 21, 2024
@PureWeen PureWeen added this to the Backlog milestone Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-map Map / Maps platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants