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
21.99k stars 1.72k forks source link

Crash on ios when open new screen or navigate back to it #24032

Closed DmitryNikiforovCoherent closed 5 days ago

DmitryNikiforovCoherent commented 1 month ago

Description

It seems, there were similar issues previously https://github.com/dotnet/maui/issues/23139, but now issue appeared after upgrade to maui to 8.0.70 and removing .UseMauiCompatibility() Sometimes view try to created with NativeHandle argument in constructor

This crash can appeared with Microsoft.Maui.Platform.ContentView|LayoutView and some custom views(so, adding constructor with ObjCRuntime.NativeHandle resolve issue for custom views, but no any options to resolve crashes with ContentView, LayoutView)

Steps to Reproduce

Sometimes just randomly appeared when navigate to new screen or navigate back to existing

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

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

No response

Did you find any workaround?

For custom views we can just add constructor with ObjCRuntime.NativeHandle handle, but no any ways to fix ios ContentView/LayoutView

Relevant log output

Unhandled managed exception: Failed to marshal the Objective-C object 0x14177b170 (type: Microsoft_Maui_Platform_ContentView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.ContentView' does not have a constructor that takes one NativeHandle argument). (ObjCRuntime.RuntimeException)
   at ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.ConstructNSObject[UIView](IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle , Boolean )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr )
   at UIKit.UIView.get_Superview()
   at Microsoft.Maui.Platform.MauiView.SetNeedsLayout()
github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

DmitryNikiforovCoherent commented 1 month ago

@jfversluis Could you help, what can be the reason of creating ios view with additional parameter in ctor? As I see from logs, sometimes this happens just during simple navigatio

jfversluis commented 1 month ago

Without a reproduction project of sorts its very hard to say something useful about it unfortunately

DmitryNikiforovCoherent commented 1 month ago

As I investigate, one of case(but not only): this happened, when we have CachedImage from FFImageLoading library on the ContentPage

  1. Screen started, start load data
  2. User tap on button, that hide part of page content, including CachedImage(custom implementation of tab behavior)
  3. Data loaded, ImageSource set for hidden CachedImage, and CachedImageHandler.ImageLoadingSizeChanged called
  4. Maui tries to redraw all parent and for some reason try to recreate LayoutView
ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x11ef7ad40 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument).
   at ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.ConstructNSObject[UIView](IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle , Boolean )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle )
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr )
   at UIKit.UIView.get_Superview()
   at Microsoft.Maui.Platform.MauiView.SetNeedsLayout()
   at Microsoft.Maui.Platform.MauiView.SetNeedsLayout()
   at Microsoft.Maui.Handlers.ViewHandler.MapInvalidateMeasure(IViewHandler handler, IView view, Object args)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, Object o)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at Microsoft.Maui.Controls.VisualElement.InvalidateMeasureOverride()
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.InvalidateMeasure()
   at Microsoft.Maui.Controls.VisualElement.InvalidateMeasureInternal(InvalidationTrigger trigger)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.Controls.IVisualElementController.InvalidateMeasure(InvalidationTrigger trigger)
   at FFImageLoading.Maui.Platform.CachedImageHandler.<>c__DisplayClass15_0.<ImageLoadingSizeChanged>b__0()
   at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass1_0.<DispatchAsync>b__0()
   at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass0_0`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<DispatchAsync>b__0()
--- End of stack trace from previous location ---
   at FFImageLoading.Maui.Platform.CachedImageHandler.ImageLoadingSizeChanged(CachedImage element, Boolean isLoading)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
DmitryNikiforovCoherent commented 1 month ago

So, it seems, that when in MauiView.SetNeedsLayout try to get Superview, crash appeared if Superview is not visible

DmitryNikiforovCoherent commented 1 month ago

In this project reproduced not very often, need try to open several times and switch between tabs. cc @jfversluis MauiApp1.zip

reid-kirkpatrick commented 1 month ago

@DmitryNikiforovCoherent @jfversluis @Redth we are also seeing this with FFImageLoading as we convert our app. It's one of the last major issues we're having. Any ideas?

jfversluis commented 1 month ago

I see the repro also uses FFImageLoading. If we take FFImageLoading out of the equation, does it work then?

Just to establish if this is something in MAUI or FFImageLoading?

DmitryNikiforovCoherent commented 1 month ago

I'm not sure, according to the analytics, sometimes we also faced with this issue with next logs Unhandled managed exception: Failed to marshal the Objective-C object 0x14177b170 (type: Microsoft_Maui_Platform_ContentView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.ContentView' does not have a constructor that takes one NativeHandle argument). (ObjCRuntime.RuntimeException) at ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle ) at ObjCRuntime.Runtime.ConstructNSObject[UIView](IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle ) at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle , Boolean ) at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle ) at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr ) at UIKit.UIView.get_Superview() at Microsoft.Maui.Platform.MauiView.SetNeedsLayout()

Without FFImageLoading.Maui.Platform.CachedImageHandler.ImageLoadingSizeChanged in stacktrace. But with FFImageLoading it's the simplest way to reproduce, because it has standard behavior to change control size after page loaded. As I mentioned above, it seems, sometimes, if control hidden, and child try to change size, get_Superview throw an exception Will try to reproduce this with simple control like Label tomorrow

DmitryNikiforovCoherent commented 1 month ago

@DmitryNikiforovCoherent @jfversluis @Redth we are also seeing this with FFImageLoading as we convert our app. It's one of the last major issues we're having. Any ideas?

If you need to fix fast, just downgrade maui to 8.0.40. For me this helps

mackayn commented 1 month ago

@jfversluis @PureWeen @samhouts Seeing this in production in our iOS app making it incredibly unstable for users, as mentioned above, this happens constantly in regular navigation and no FFImageLoading library in our app. This is a critical issue for us.

MAUI 8.0.80 iOS 16.5 to 17.6

SIGABRT: Failed to marshal the Objective-C object 0x153507310 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument).

ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
ObjCRuntime.Runtime.ConstructNSObject[UIView](IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr , IntPtr , RuntimeMethodHandle , Boolean )
UIKit.UIView.get_Superview()
Microsoft.Maui.Platform.LayoutView.WillRemoveSubview(UIView uiview)
ObjCRuntime.Runtime.RethrowManagedException(IntPtr )
UIKit.UIView.AddSubview(UIView )
Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler)
Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page)
Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view)
Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.CreateViewControllerForPage(Page page)
Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.OnPushAsync(Page page, Boolean animated)
Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.<ViewDidLoad>b__53_0(Page p)
System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
Foundation.NSAsyncSynchronizationContextDispatcher.Apply()
ObjCRuntime.Runtime.ThrowException(IntPtr )
UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
UIKit.UIApplication.Main(String[] , Type , Type )
X.Mobile.Primary.Program.Main(String[] args)
mackayn commented 1 month ago

@DmitryNikiforovCoherent @jfversluis @Redth we are also seeing this with FFImageLoading as we convert our app. It's one of the last major issues we're having. Any ideas?

If you need to fix fast, just downgrade maui to 8.0.40. For me this helps

Wish we could, production software relies on higher dependencies such as Prism which relies on 8.0.60. There has to be a stable version on .NET8 MAUI before we entertain .NET9, this is costing companies money now.

PureWeen commented 1 month ago

Is there anyone that's hitting this issue that's using Shell?

I have a theory, but it's something that'll only manifest if you're not using shell

mackayn commented 1 month ago

Is there anyone that's hitting this issue that's using Shell?

I have a theory, but it's something that'll only manifest if you're not using shell

100% not using shell.

DmitryNikiforovCoherent commented 1 month ago

Is there anyone that's hitting this issue that's using Shell?

I have a theory, but it's something that'll only manifest if you're not using shell

The same, we are not using shell

reid-kirkpatrick commented 1 month ago

Is there anyone that's hitting this issue that's using Shell?

I have a theory, but it's something that'll only manifest if you're not using shell

We are using shell

PureWeen commented 1 month ago

Is there anyone that's hitting this issue that's using Shell? I have a theory, but it's something that'll only manifest if you're not using shell

We are using shell

Do you have a stack trace?

reid-kirkpatrick commented 1 month ago

Is there anyone that's hitting this issue that's using Shell? I have a theory, but it's something that'll only manifest if you're not using shell

We are using shell

Do you have a stack trace?

ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x11a472110 (type: Microsoft_Maui_Platform_ContentView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.ContentView' does not have a constructor that takes one NativeHandle argument).
   at ObjCRuntime.Runtime.MissingCtor(IntPtr ptr, IntPtr klass, Type type, MissingCtorResolution resolution, IntPtr sel, RuntimeMethodHandle method_handle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 1323
   at ObjCRuntime.Runtime.ConstructNSObject[UIView](IntPtr ptr, Type type, MissingCtorResolution missingCtorResolution, IntPtr sel, RuntimeMethodHandle method_handle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 1454
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr ptr, IntPtr sel, RuntimeMethodHandle method_handle, Boolean evenInFinalizerQueue) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 1791
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr ptr, IntPtr sel, RuntimeMethodHandle method_handle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 1753
   at ObjCRuntime.Runtime.GetNSObject[UIView](IntPtr ptr) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 1748
   at UIKit.UIView.get_Superview() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIView.g.cs:line 4819
   at Microsoft.Maui.Platform.MauiView.SetNeedsLayout()
   at Microsoft.Maui.Platform.ViewExtensions.InvalidateMeasure(UIView platformView, IView view)
   at Microsoft.Maui.Handlers.ViewHandler.MapInvalidateMeasure(IViewHandler handler, IView view, Object args)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, Object o)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at Microsoft.Maui.Controls.VisualElement.InvalidateMeasureOverride()
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.InvalidateMeasure()
   at Microsoft.Maui.Controls.VisualElement.InvalidateMeasureInternal(InvalidationTrigger trigger)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.Controls.IVisualElementController.InvalidateMeasure(InvalidationTrigger trigger)
   at FFImageLoading.Maui.Platform.CachedImageHandler.<>c__DisplayClass15_0.<ImageLoadingSizeChanged>b__0()
   at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass1_0.<DispatchAsync>b__0()
   at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass0_0`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<DispatchAsync>b__0()

edit: I'll try to get one that is more helpful, but that's what I have right now edit2: updated @PureWeen

PureWeen commented 1 month ago

@DmitryNikiforovCoherent I tried to reproduce with your sample but wasn't able to

There are some nugets here https://dev.azure.com/xamarin/public/_build/results?buildId=121542&view=results

if anyone is able to download those and test that would be helpful

reid-kirkpatrick commented 1 month ago

@DmitryNikiforovCoherent I tried to reproduce with your sample but wasn't able to

There are some nugets here https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=10039640&view=artifacts&pathAsName=false&type=publishedArtifacts

if anyone is able to download those and test that would be helpful

Happy to help test, but I don't have access to that link

DmitryNikiforovCoherent commented 1 month ago

@DmitryNikiforovCoherent I tried to reproduce with your sample but wasn't able to

There are some nugets here https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=10039640&view=artifacts&pathAsName=false&type=publishedArtifacts

if anyone is able to download those and test that would be helpful

Yes, not sure, but in this test project crash reproduced not often(however in more complex real project reproduced each time), I restarted several times before crash appeared

Don't have access to this, too

PureWeen commented 1 month ago

alright @reid-kirkpatrick @DmitryNikiforovCoherent

I think I found the right pipeline :-) I updated the link and kicked off a build It'll take about an hour or so then you can download nugets

PureWeen commented 1 month ago

looks like they've finished cooking

The interface to grab those artifacts can be a little confusing

There are three dots you click and then from there download the whole nuget folder

image

mackayn commented 1 month ago

alright @reid-kirkpatrick @DmitryNikiforovCoherent

I think I found the right pipeline :-) I updated the link and kicked off a build It'll take about an hour or so then you can download nugets

I have tested with the pre-80.8.1 nugets and the app is no longer crashing. We were seeing crashes between 2 & 10 page navigations before but performed over 100 navigations with no issue, nice work. Other stuff seems borked but this is a pre-release and have no intention of running with these packages as it's way to early.

DmitryNikiforovCoherent commented 1 month ago

Tested locally, it seems, crash is gone! Great, thank you @PureWeen Will recheck with automation tests, notify in 1-2 hours after all test cases passed

mackayn commented 1 month ago

@PureWeen Any timeline on when 80.8.1 might appear ? (roughly)

reid-kirkpatrick commented 1 month ago

Yep, seems to be working here too @PureWeen. Thank you!

pboisso commented 1 month ago

Also interested to know when 80.8.1 will be out. This is an issue for us also.

PureWeen commented 1 month ago

Other stuff seems borked but this is a pre-release and have no intention of running with these packages as it's way to early.

@mackayn can you elaborate some? Is it borked because of these changes specifically?

Most of the chances from these packages shouldn't really cause additional problem. My main concern is that they would just move the problem down the road.

Like, if there's other code that's calling "SuperView" somewhere and triggering the same path

mackayn commented 1 month ago

Other stuff seems borked but this is a pre-release and have no intention of running with these packages as it's way to early.

@mackayn can you elaborate some? Is it borked because of these changes specifically?

Most of the chances from these packages shouldn't really cause additional problem. My main concern is that they would just move the problem down the road.

Like, if there's other code that's calling "SuperView" somewhere and triggering the same path

Apologies @PureWeen I was testing on an unstable branch. Just added the 8.0.81-ci.net8.24413.37 packages to our stable develop branch and working perfectly, no navigation issues. All good here !

sumowesley commented 1 month ago

I'm having the same issue when running on 8.0.81. Going back to 8.0.40 gets rid of the crash, but does increase the number of detected memory leaks.

Error message Failed to marshal the Objective-C object 0x1155df190 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument).

Trace information (copied from Sentry) ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x1155df190 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument). ?, in void Runtime.MissingCtor(IntPtr, IntPtr, Type, MissingCtorResolution, IntPtr, RuntimeMethodHandle) ?, in UIView Runtime.ConstructNSObject(IntPtr, Type, MissingCtorResolution, IntPtr, RuntimeMethodHandle) ?, in UIView Runtime.GetNSObject(IntPtr, IntPtr, RuntimeMethodHandle, bool) ?, in UIView UIView.get_Superview() ?, in void MauiView.SetNeedsLayout() x 2 ?, in void ViewExtensions.InvalidateMeasure(UIView platformView, IView view) ?, in void ViewHandler.MapInvalidateMeasure(IViewHandler handler, IView view, object args) ?, in void CommandMapper<TVirtualView, TViewHandler>.Add(string key, Action<TViewHandler, TVirtualView> action)+(IElementHandler h, IElement v, object o) => { } ?, in void CommandMapper.InvokeCore(string key, IElementHandler viewHandler, IElement virtualView, object args) ?, in void ElementHandler.Invoke(string command, object args) ?, in void Layout.InvalidateMeasureOverride() ?, in void VisualElement.Microsoft.Maui.IView.InvalidateMeasure() ?, in void Layout.Microsoft.Maui.Controls.IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) ?, in void PaddingElement.OnPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue) ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent) ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) ?, in void BindingExpression.ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget, SetterSpecificity specificity) ?, in void BindingExpression.Apply(bool fromTarget) ?, in void BindingExpressionPart.PropertyChanged(object sender, PropertyChangedEventArgs args)+() => { } ?, in void DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action) ?, in void BindingExpressionPart.PropertyChanged(object sender, PropertyChangedEventArgs args) ?, in void WeakPropertyChangedProxy.OnPropertyChanged(object sender, PropertyChangedEventArgs e) ?, in void BindableObject.OnPropertyChanged(string propertyName) ?, in void Insets.OnPropertyChanged(string propertyName) x 2 ?, in void Insets.SetEnabled(bool enabled) ?, in void Insets.UpdateEdgeToEdge(Page page) ?, in void Insets.SetupPage(Page page) ?, in void Insets.PagePropertyChanged(object sender, PropertyChangedEventArgs e) ?, in void Element.OnPropertyChanged(string propertyName) ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent) ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) ?, in void BindableObject.SetValue(BindablePropertyKey propertyKey, object value) ?, in void VisualElement.Microsoft.Maui.Controls.IWindowController.set_Window(Window value) ?, in void PropertyPropagationExtensions.PropagateWindow(Element target, Element source) ?, in void PropertyPropagationExtensions.SetWindowFromParent(Element child) ?, in void PropertyPropagationExtensions.PropagatePropertyChanged(string propertyName, Element element, IEnumerable children) ?, in void VisualElement.Microsoft.Maui.Controls.IPropertyPropagationController.PropagatePropertyChanged(string propertyName) ?, in void Element.OnParentSet() ?, in void NavigableElement.OnParentSet() ?, in void Page.OnParentSet() ?, in void Element.SetParent(Element value) ?, in void Element.OnChildAdded(Element child) ?, in void ShellSection.OnChildAdded(Element child) ?, in void Element.AddLogicalChild(Element element) ?, in void ShellSection.AddPage(Page page) ?, in Task ShellSection.OnPushAsync(Page page, bool animated) ?, in async Task ShellSection.PushStackOfPages(List pages, bool? animate) ?, in async Task ShellSection.PrepareCurrentStackForBeingReplaced(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, bool? animate, List globalRoutes, bool isRelativePopping) ?, in async Task ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, bool? animate, bool isRelativePopping) ?, in async Task ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest) File "ShellProxy.cs", line 63, in async Task ShellProxy.CommitNavigationAsync(Action completeAction) await shell.GoToAsync(targetState, true).ConfigureAwait(true); File "NavigationService.cs", line 262, in async Task NavigationService.ExecuteRelativeNavigationAsync(INavigationInfo navigation, HashSet disposeBag, IShellSectionProxy section, List stack, bool sendAppearingToTarget, bool ignoreGuards, Func onCheckingGuardAsync) await shellProxy.CommitNavigationAsync().ConfigureAwait(true); File "NavigationService.cs", line 86, in async Task NavigationService.GoToAsync(INavigationInfo navigation)+(?) => { } x 2 => ExecuteRelativeNavigationAsync(navigation, disposeBag, ignoreGuards: ignoreGuards).ConfigureAwait(true), File "NavigationService.cs", line 521, in async Task NavigationService.ExecuteNavigationAsync(Func<Task> navigationFunc) var result = await navigationFunc().ConfigureAwait(true); File "NavigationService.cs", line 72, in async Task NavigationService.GoToAsync(INavigationInfo navigation) return await ExecuteNavigationAsync(async () => ?, in async Task OverviewPageViewModel.ShowCasesSearch() ?, in async void AsyncRelayCommand.AwaitAndThrowIfFailed(Task) ?, in void Task.ThrowAsync(Exception, SynchronizationContext)+(object state) => { } ?, in void NSAsyncSynchronizationContextDispatcher.Apply() ?, in int UIApplication.UIApplicationMain(int, string[], IntPtr, IntPtr) ?, in void UIApplication.Main(string[], Type, Type) ?, in void Program.Main(string[] args)

DmitryNikiforovCoherent commented 1 month ago

I'm having the same issue when running on 8.0.81. Going back to 8.0.40 gets rid of the crash, but does increase the number of detected memory leaks.

Error message Failed to marshal the Objective-C object 0x1155df190 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument).

Trace information (copied from Sentry) ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x1155df190 (type: Microsoft_Maui_Platform_LayoutView). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.LayoutView' does not have a constructor that takes one NativeHandle argument). ?, in void Runtime.MissingCtor(IntPtr, IntPtr, Type, MissingCtorResolution, IntPtr, RuntimeMethodHandle) ?, in UIView Runtime.ConstructNSObject(IntPtr, Type, MissingCtorResolution, IntPtr, RuntimeMethodHandle) ?, in UIView Runtime.GetNSObject(IntPtr, IntPtr, RuntimeMethodHandle, bool) ?, in UIView UIView.get_Superview() ?, in void MauiView.SetNeedsLayout() x 2 ?, in void ViewExtensions.InvalidateMeasure(UIView platformView, IView view) ?, in void ViewHandler.MapInvalidateMeasure(IViewHandler handler, IView view, object args) ?, in void CommandMapper<TVirtualView, TViewHandler>.Add(string key, Action<TViewHandler, TVirtualView> action)+(IElementHandler h, IElement v, object o) => { } ?, in void CommandMapper.InvokeCore(string key, IElementHandler viewHandler, IElement virtualView, object args) ?, in void ElementHandler.Invoke(string command, object args) ?, in void Layout.InvalidateMeasureOverride() ?, in void VisualElement.Microsoft.Maui.IView.InvalidateMeasure() ?, in void Layout.Microsoft.Maui.Controls.IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) ?, in void PaddingElement.OnPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue) ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent) ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) ?, in void BindingExpression.ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget, SetterSpecificity specificity) ?, in void BindingExpression.Apply(bool fromTarget) ?, in void BindingExpressionPart.PropertyChanged(object sender, PropertyChangedEventArgs args)+() => { } ?, in void DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action) ?, in void BindingExpressionPart.PropertyChanged(object sender, PropertyChangedEventArgs args) ?, in void WeakPropertyChangedProxy.OnPropertyChanged(object sender, PropertyChangedEventArgs e) ?, in void BindableObject.OnPropertyChanged(string propertyName) ?, in void Insets.OnPropertyChanged(string propertyName) x 2 ?, in void Insets.SetEnabled(bool enabled) ?, in void Insets.UpdateEdgeToEdge(Page page) ?, in void Insets.SetupPage(Page page) ?, in void Insets.PagePropertyChanged(object sender, PropertyChangedEventArgs e) ?, in void Element.OnPropertyChanged(string propertyName) ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent) ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) ?, in void BindableObject.SetValue(BindablePropertyKey propertyKey, object value) ?, in void VisualElement.Microsoft.Maui.Controls.IWindowController.set_Window(Window value) ?, in void PropertyPropagationExtensions.PropagateWindow(Element target, Element source) ?, in void PropertyPropagationExtensions.SetWindowFromParent(Element child) ?, in void PropertyPropagationExtensions.PropagatePropertyChanged(string propertyName, Element element, IEnumerable children) ?, in void VisualElement.Microsoft.Maui.Controls.IPropertyPropagationController.PropagatePropertyChanged(string propertyName) ?, in void Element.OnParentSet() ?, in void NavigableElement.OnParentSet() ?, in void Page.OnParentSet() ?, in void Element.SetParent(Element value) ?, in void Element.OnChildAdded(Element child) ?, in void ShellSection.OnChildAdded(Element child) ?, in void Element.AddLogicalChild(Element element) ?, in void ShellSection.AddPage(Page page) ?, in Task ShellSection.OnPushAsync(Page page, bool animated) ?, in async Task ShellSection.PushStackOfPages(List pages, bool? animate) ?, in async Task ShellSection.PrepareCurrentStackForBeingReplaced(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, bool? animate, List globalRoutes, bool isRelativePopping) ?, in async Task ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, bool? animate, bool isRelativePopping) ?, in async Task ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest) File "ShellProxy.cs", line 63, in async Task ShellProxy.CommitNavigationAsync(Action completeAction) await shell.GoToAsync(targetState, true).ConfigureAwait(true); File "NavigationService.cs", line 262, in async Task NavigationService.ExecuteRelativeNavigationAsync(INavigationInfo navigation, HashSet disposeBag, IShellSectionProxy section, List stack, bool sendAppearingToTarget, bool ignoreGuards, Func onCheckingGuardAsync) await shellProxy.CommitNavigationAsync().ConfigureAwait(true); File "NavigationService.cs", line 86, in async Task NavigationService.GoToAsync(INavigationInfo navigation)+(?) => { } x 2 => ExecuteRelativeNavigationAsync(navigation, disposeBag, ignoreGuards: ignoreGuards).ConfigureAwait(true), File "NavigationService.cs", line 521, in async Task NavigationService.ExecuteNavigationAsync(Func navigationFunc) var result = await navigationFunc().ConfigureAwait(true); File "NavigationService.cs", line 72, in async Task NavigationService.GoToAsync(INavigationInfo navigation) return await ExecuteNavigationAsync(async () => ?, in async Task OverviewPageViewModel.ShowCasesSearch() ?, in async void AsyncRelayCommand.AwaitAndThrowIfFailed(Task) ?, in void Task.ThrowAsync(Exception, SynchronizationContext)+(object state) => { } ?, in void NSAsyncSynchronizationContextDispatcher.Apply() ?, in int UIApplication.UIApplicationMain(int, string[], IntPtr, IntPtr) ?, in void UIApplication.Main(string[], Type, Type) ?, in void Program.Main(string[] args)

Have you checked pre release nuget https://dev.azure.com/xamarin/public/_build/results?buildId=121542&view=results instead of 8.0.81

sumowesley commented 1 month ago

Have you checked pre release nuget https://dev.azure.com/xamarin/public/_build/results?buildId=121542&view=results instead of 8.0.81

@DmitryNikiforovCoherent, thank you for the link. I've downloaded and extracted the contents of the ZIP file. I'm not sure I'm brave enough to deploy these. Going back to 8.0.40 was simple enough; I'll have a look to see what's involved as we have four dev machines (two Mac and two Windows).

It would be good to get an estimated release date of the 8.0.81.

PureWeen commented 3 weeks ago

SR8.1 should be out early next week

PureWeen commented 2 weeks ago

Just a heads up :-/

Unfortunately, a regression was found with this fix so we'll need to roll it back for SR8

We still have it planned as part of SR9.

I'll update the thread here when we have nightlies ready with some updated fixes.

pboisso commented 2 weeks ago

When is SR9 expected to go out? This is high priority to us. Waiting for a fix to release.

mackayn commented 2 weeks ago

Just a heads up :-/

Unfortunately, a regression was found with this fix so we'll need to roll it back for SR8

We still have it planned as part of SR9.

I'll update the thread here when we have nightlies ready with some updated fixes.

Would be good to get an update as this is a critical issue. We can't wait a couple of weeks.

ardentra commented 2 weeks ago

Just a heads up :-/

Unfortunately, a regression was found with this fix so we'll need to roll it back for SR8

We still have it planned as part of SR9.

I'll update the thread here when we have nightlies ready with some updated fixes.

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

thisisthekap commented 2 weeks ago

@PureWeen Which regression specifically? This information could help us in justifying if using a custom build is a viable option.

PureWeen commented 2 weeks ago

SR9 should be out next week If we were to try and roll a new SR8 it would probably end up being released about the same time as SR9 once it was tested/validated

Speaking of, if anyone can test the nugets from https://github.com/dotnet/maui/pull/24477 that would be helpful

mackayn commented 2 weeks ago

SR9 should be out next week If we were to try and roll a new SR8 it would probably end up being released about the same time as SR9 once it was tested/validated

Speaking of, if anyone can test the nugets from #24477 that would be helpful

If you could provide a link I can test, we're having to go with 8.0.81-ci.net8.24413.37 at present as we can't wait any longer and it's more stable than 8.0.80, if you provide a link I can test before we put out a very hot fix.

DmitryNikiforovCoherent commented 2 weeks ago

SR9 should be out next week If we were to try and roll a new SR8 it would probably end up being released about the same time as SR9 once it was tested/validated Speaking of, if anyone can test the nugets from #24477 that would be helpful

If you could provide a link I can test, we're having to go with 8.0.81-ci.net8.24413.37 at present as we can't wait any longer and it's more stable than 8.0.80, if you provide a link I can test before we put out a very hot fix.

You can check current 8.0.81-ci from link https://dev.azure.com/xamarin/public/_build/results?buildId=121542&view=results (As @PureWeen provided above)

  1. Download nuget-macos folder, add to project folder
  2. Update Directory.Build.props with path to this folder $(MSBuildThisFileDirectory)/{folder}/nuget-macos
  3. Update version for maui packages to 8.0.81-ci.net8.24413.37 For me smoke test was successful, but to be sure will wait for stable release(for now have downgraded to version 8.0.40, works well)
mackayn commented 2 weeks ago

SR9 should be out next week If we were to try and roll a new SR8 it would probably end up being released about the same time as SR9 once it was tested/validated Speaking of, if anyone can test the nugets from #24477 that would be helpful

If you could provide a link I can test, we're having to go with 8.0.81-ci.net8.24413.37 at present as we can't wait any longer and it's more stable than 8.0.80, if you provide a link I can test before we put out a very hot fix.

You can check current 8.0.81-ci from link https://dev.azure.com/xamarin/public/_build/results?buildId=121542&view=results (As @PureWeen provided above)

  1. Download nuget-macos folder, add to project folder
  2. Update Directory.Build.props with path to this folder $(MSBuildThisFileDirectory)/{folder}/nuget-macos
  3. Update version for maui packages to 8.0.81-ci.net8.24413.37 For me smoke test was successful, but to be sure will wait for stable release(for now have downgraded to version 8.0.40, works well)

Thanks, I am already using those libs with no issue, I was asking if I could get the nugets for #24477 which is a different issue (although related)

PureWeen commented 2 weeks ago

The latest nightlies should have the new version of the fix from #24477

https://github.com/dotnet/maui/wiki/Nightly-Builds

Let me know if that works

If not, I have an idea about how to add that code back in.

But if I don't have to :-) that'd be nice

Going to reopen this issue until I get some validation from y'all so we don't miss it

pboisso commented 2 weeks ago

Still crashing here with build 82.

mackayn commented 2 weeks ago

@PureWeen We couldn't wait so have a beta build release already out in testflight using 8.0.81-ci.net8.24413.37 with no navigation issues in release mode, client is testing atm. Once we have that out I'll re-test with the nightly builds

PureWeen commented 2 weeks ago

Still crashing here with build 82.

yea, we rolled the change back for 82 because of a regression it caused

There's a different fix now on our main branch that you can test with nightlies We'll release this in the next couple of weeks officially

PureWeen commented 2 weeks ago

@PureWeen We couldn't wait so have a beta build release already out in testflight using 8.0.81-ci.net8.24413.37 with no navigation issues in release mode, client is testing atm. Once we have that out I'll re-test with the nightly builds

Here's what regressed

https://github.com/dotnet/maui/issues/24434

Not sure if this will apply to any of your scenarios but might help you know what to focus your testing on.

mackayn commented 1 week ago

@PureWeen

Just FYI, our iOS app went out into store release with 8.0.81-ci.net8.24413.37, not seeing this crash at all anymore so the fix is good, didn't appear in beta testing either. This app has over 100 pages and a lot of navigation interaction per session.

PureWeen commented 1 week ago

@reid-kirkpatrick @DmitryNikiforovCoherent @pboisso @sumowesley @thisisthekap @mackayn

If you have a chance to test the latest nightly can you see if it works there as well?

https://github.com/dotnet/maui/wiki/Nightly-Builds

Want to make sure this gets fixed for you all in SR9