dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

`ViewHandler<TVirtualView, TPlatformView>.PlatformView` getter throws `InvalidOperationException` #25908

Open BioTurboNick opened 4 days ago

BioTurboNick commented 4 days ago

Description

I just released a new version of my app with MAUI 9, and in the wild (via Sentry.io) found that ViewHandler<TVirtualView, TPlatformView>.PlatformView property getter is sometimes throwing an InvalidOperationException because the underlying PlatformView property is null. Specifically, this is a custom handler that inherits from ContentViewHandler.

https://github.com/dotnet/maui/blob/083ffa88d99c84316960d38c81eb2522eef1c91b/src/Core/src/Handlers/View/ViewHandlerOfT.cs#L34-L38

It may occur during teardown of a page, and so will be hard to reproduce. Log showed it occurred after a NavigatedTo.

I will update if and when I learn more.

Steps to Reproduce

n/a

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.61 SR6.1

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

jfversluis commented 4 days ago

Unfortunately, without any more information its hard to make this actionable. A reproduction or at the very least a stack trace would be needed to be able to say something useful about this.

What does your custom renderer look like? Does this app also have an iOS version, does it also happen there?

BioTurboNick commented 4 days ago

Your comment spurred me to take a closer look at my Handlers. I may have been using an ill-advised pattern, with an async void event handler inside the Handler object itself, rather than handling the touch events in an extension of the platform object itself.

I suspect addressing this will fix the issue, although I don't recall why I did it that way in the first place... I'll update and close if that works.

ninachen03 commented 3 days ago

If you solve the problem, please let us know, thank you

dotnet-policy-service[bot] commented 3 days ago

Hi @BioTurboNick. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.