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

MAUI iOS Crashes when navigating with Shell #17034

Closed
Juansero29 opened this issue Aug 28, 2023 · 1 comment
Closed

MAUI iOS Crashes when navigating with Shell #17034

Juansero29 opened this issue Aug 28, 2023 · 1 comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout high It doesn't work at all, crashes or has a big impact. platform/iOS 🍎 t/bug Something isn't working

Comments

@Juansero29
Copy link

Description

I have been bulding an app for Android/iOS. The app currently works as intended on Android. But when executing the same app on ios, I get an error when trying to execute navigation to pages.

It seems to be tied to not executing code on the main thread when it should be executed there. I do use the GoToAsync method to navigate.

I have tried these different methods, but none works:

         Application.Current?.Dispatcher.Dispatch(async () => {
                    await Shell.Current.GoToAsync("//chores");
                });
             MainThread.BeginInvokeOnMainThread(async () =>
                {
                    await Shell.Current.GoToAsync("//chores");
                });

Seems like if when navigating from my ShellPageViewModel the method "SetValueFromRenderer" is somehow called, which triggers some visual modifications that should happen only in the UI Thread. But even when forcing navigation inside the UI thread I can't get it to work.

Steps to Reproduce

  1. Create MAUI app
  2. Execute with iOS simulator
  3. Navigate with Shell to new page while async
  4. App crashes

Link to public reproduction project repository

No response

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

7.0.92/7.0.100

Did you find any workaround?

No.

Relevant log output

The error is the following:
`"UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread."`
stack trace:

at UIKit.UIApplication.EnsureUIThread()\n  
   at UIKit.UIView.set_BackgroundColor(UIColor value)\n  
   at Microsoft.Maui.Platform.ViewExtensions.UpdateBackground(UIView platformView, Paint paint, IButtonStroke stroke)\n  
   at Microsoft.Maui.Platform.ViewExtensions.UpdateBackground(UIView platformView, IView view)\n  
   at Microsoft.Maui.Handlers.LayoutHandler.MapBackground(ILayoutHandler handler, ILayout layout)\n  
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.ILayoutHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)\n  
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)\n  
   at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property)\n  
   at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property)\n  
   at Microsoft.Maui.Controls.VisualElement.MapBackgroundColor(IViewHandler handler, IView view)\n  
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.IViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)\n  
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)\n  
   at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property)\n  
   at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property)\n  
   at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)\n  
   at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, Boolean fromStyle, Boolean checkAccess)\n  
   at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, Boolean fromStyle)\n  
   at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, Boolean fromStyle)\n  
   at Microsoft.Maui.Controls.VisualStateManager.GoToState(VisualElement visualElement, String name)\n  
   at Microsoft.Maui.Controls.Platform.Compatibility.UIContainerCell.UpdateVisualState()\n  
   at Microsoft.Maui.Controls.Platform.Compatibility.UIContainerCell.OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)\n  
   at Microsoft.Maui.Controls.BindableObject.OnPropertyChanged(String propertyName)\n  
   at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)\n  
   at Microsoft.Maui.Controls.BaseShellItem.OnPropertyChanged(String propertyName)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindablePropertyKey propertyKey, Object value)\n  
   at Microsoft.Maui.Controls.Shell.UpdateChecked(Element root, Boolean isChecked)\n  
   at Microsoft.Maui.Controls.Shell.UpdateChecked(Element root, Boolean isChecked)\n  
   at Microsoft.Maui.Controls.Shell.UpdateChecked(Element root, Boolean isChecked)\n  
   at Microsoft.Maui.Controls.Shell.UpdateChecked(Element root, Boolean isChecked)\n  
   at Microsoft.Maui.Controls.Shell.OnCurrentItemChanged(BindableObject bindable, Object oldValue, Object newValue)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)\n  
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes)\n  
   at Microsoft.Maui.Controls.Element.SetValueFromRenderer(BindableProperty property, Object value)\n  
   at Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)\n  
   at Nou.ViewModels.ShellPageViewModel.Load(Object parameter) in /Users/juansero29/Projects/Nou/Nou/ViewModels/ShellPageViewModel.cs:line 124\n  
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)\n  
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()\n  
   at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object workItem, Thread currentThread)\n  
   at System.Threading.ThreadPoolWorkQueue.Dispatch()\n  
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()\n  
   at System.Threading.Thread.StartCallback()"
@Juansero29 Juansero29 added the t/bug Something isn't working label Aug 28, 2023
@samhouts samhouts added platform/iOS 🍎 area-controls-shell Shell Navigation, Routes, Tabs, Flyout high It doesn't work at all, crashes or has a big impact. labels Aug 28, 2023
@samhouts
Copy link
Member

Duplicate of #16862

@samhouts samhouts marked this as a duplicate of #16862 Aug 28, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout high It doesn't work at all, crashes or has a big impact. platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants