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.83k stars 1.67k forks source link

In .NET 8 IOS platform getting exception while remove the child from the current layout. #22951

Open MohanrajSF3559 opened 3 weeks ago

MohanrajSF3559 commented 3 weeks ago

Description

I have attached the sample. Same sample properly working in .NET 7. There is now change in our source level. But facing exception in .NET 8 in IOS alone. Same sample working fine in windows, Mac Android devices.

Steps to Reproduce

  1. Run the sample.
  2. Click the crop icon from the bottom of the image editor control.
  3. Click the crop option icon.
  4. Click the crop image button.
  5. You got a exception.

Link to public reproduction project repository

https://github.com/MohanrajSF3559/ImageEditor-Mopup-Issue

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

8.0.0-preview.1.7762

Affected platforms

iOS

Affected platform versions

iOS 16.2

Did you find any workaround?

NA

Relevant log output

No response

drasticactions commented 3 weeks ago

Your exception is

System.InvalidOperationException: MauiContext should have been set on parent.
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Microsoft.Maui.Handlers.LayoutHandler.MapRemove(ILayoutHandler handler, ILayout layout, Object arg)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, 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.Layout.NotifyHandler(String action, Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index)
   at Microsoft.Maui.Controls.Layout.Remove(IView child)
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.RemoveCropView()
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.Syncfusion.Maui.ImageEditor.IToolbarActions.CancelEdit()
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.HandleItemTapped(SfToolbarItem tappedItem, SfToolbarItem previousItem)
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.OnToolbarItemTapped(Object sender, ToolbarTappedEventArgs e)
   at Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)
   at Syncfusion.Maui.Core.Internals.SfToolbarLayout.Syncfusion.Maui.Core.Internals.ITapGestureListener.OnTap(TapEventArgs e)
   at Syncfusion.Maui.Core.Internals.GestureDetector.OnTapped(Point touchPoint, Int32 tapCount)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.OnTap(GestureDetector gestureDetector)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.<>c__DisplayClass1_0.<.ctor>b__0()
   at UIKit.UIGestureRecognizer.ParameterlessDispatch.Activated() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIGestureRecognizer.cs:line 107
--- End of stack trace from previous location ---
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2594
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 60
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at MauiMopupsSample.Program.Main(String[] args) in /Users/drasticactions/Developer/Work/ImageEditor-Mopup-Issue/MauiMopupsSample/MauiMopupsSample/MauiMopupsSample/Platforms/iOS/Program.cs:line 13

The important parts are

System.InvalidOperationException: MauiContext should have been set on parent.

and

Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)

IMO, this seems like a Syncfusion issue. I would direct this to them first, as I think that's the issue's root. If it is MAUI, they can circle back.

@PureWeen @mattleibow what do you all think?

ESO-ST commented 2 weeks ago

I get the same exception when using Carousel in MAUI, it started in version 8.0.60, I tested it in v8.0.40 and it works fine there. I even tried it in the latest nightly build, 8.0.70-ci.net8.24139.2 and it happens there as well. For me it takes place when I move to the 4th page of the carousel, the first 3 pages work fine, as soon as I try to move to the 4th page I get the crash.

2024-06-20 20:59:32.172790+0100 MyProject[4427:14609335] Unhandled managed exception: MauiContext should have been set on parent. (System.InvalidOperationException)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Microsoft.Maui.Handlers.LayoutHandler.MapRemove(ILayoutHandler handler, ILayout layout, Object arg)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, 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.Layout.NotifyHandler(String action, Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.FlexLayout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index)
   at Microsoft.Maui.Controls.BindableLayout.RemoveAt(IBindableLayout layout, Int32 index)
   at Microsoft.Maui.Controls.BindableLayoutController.ClearChildren(IBindableLayout layout)
   at Microsoft.Maui.Controls.BindableLayoutController.CreateChildren()
   at Microsoft.Maui.Controls.BindableLayoutController.SetItemsSource(IEnumerable itemsSource)
   at Microsoft.Maui.Controls.BindableLayoutController.set_ItemsSource(IEnumerable value)
   at Microsoft.Maui.Controls.BindableLayout.<>c.<.cctor>b__24_0(BindableObject b, Object o, Object n)
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindableObject.ApplyBindings(Boolean skipBindingContext, Boolean fromBindingContextChanged)
   at Microsoft.Maui.Controls.BindableObject.BindingContextPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue)
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
   at Microsoft.Maui.Controls.BindableObject.set_BindingContext(Object value)
   at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.Unbind()
   at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.PrepareForReuse()
   at UIKit.UICollectionView.DequeueReusableCell(NSString reuseIdentifier, NSIndexPath indexPath) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UICollectionView.g.cs:line 234
   at UIKit.UICollectionView.DequeueReusableCell(String reuseIdentifier, NSIndexPath indexPath) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UICollectionView.cs:line 23
   at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController`1[[Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetCell(UICollectionView collectionView, NSIndexPath indexPath)
   at Microsoft.Maui.Controls.Handlers.Items.CarouselViewController.GetCell(UICollectionView collectionView, NSIndexPath indexPath)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
ninachen03 commented 2 weeks ago

I can repro this issue on Visual Studio 17.11.0 Preview 2.1 ( 8.0.40) image

PureWeen commented 1 week ago

Your exception is

System.InvalidOperationException: MauiContext should have been set on parent.
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Microsoft.Maui.Handlers.LayoutHandler.MapRemove(ILayoutHandler handler, ILayout layout, Object arg)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, 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.Layout.NotifyHandler(String action, Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index)
   at Microsoft.Maui.Controls.Layout.Remove(IView child)
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.RemoveCropView()
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.Syncfusion.Maui.ImageEditor.IToolbarActions.CancelEdit()
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.HandleItemTapped(SfToolbarItem tappedItem, SfToolbarItem previousItem)
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.OnToolbarItemTapped(Object sender, ToolbarTappedEventArgs e)
   at Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)
   at Syncfusion.Maui.Core.Internals.SfToolbarLayout.Syncfusion.Maui.Core.Internals.ITapGestureListener.OnTap(TapEventArgs e)
   at Syncfusion.Maui.Core.Internals.GestureDetector.OnTapped(Point touchPoint, Int32 tapCount)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.OnTap(GestureDetector gestureDetector)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.<>c__DisplayClass1_0.<.ctor>b__0()
   at UIKit.UIGestureRecognizer.ParameterlessDispatch.Activated() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIGestureRecognizer.cs:line 107
--- End of stack trace from previous location ---
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2594
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 60
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at MauiMopupsSample.Program.Main(String[] args) in /Users/drasticactions/Developer/Work/ImageEditor-Mopup-Issue/MauiMopupsSample/MauiMopupsSample/MauiMopupsSample/Platforms/iOS/Program.cs:line 13

The important parts are

System.InvalidOperationException: MauiContext should have been set on parent.

and

Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)

IMO, this seems like a Syncfusion issue. I would direct this to them first, as I think that's the issue's root. If it is MAUI, they can circle back.

@PureWeen @mattleibow what do you all think?

Your exception is

System.InvalidOperationException: MauiContext should have been set on parent.
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Microsoft.Maui.Handlers.LayoutHandler.MapRemove(ILayoutHandler handler, ILayout layout, Object arg)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_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, 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.Layout.NotifyHandler(String action, Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index)
   at Microsoft.Maui.Controls.Layout.Remove(IView child)
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.RemoveCropView()
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.Syncfusion.Maui.ImageEditor.IToolbarActions.CancelEdit()
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.HandleItemTapped(SfToolbarItem tappedItem, SfToolbarItem previousItem)
   at Syncfusion.Maui.ImageEditor.ToolbarLayout.OnToolbarItemTapped(Object sender, ToolbarTappedEventArgs e)
   at Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)
   at Syncfusion.Maui.Core.Internals.SfToolbarLayout.Syncfusion.Maui.Core.Internals.ITapGestureListener.OnTap(TapEventArgs e)
   at Syncfusion.Maui.Core.Internals.GestureDetector.OnTapped(Point touchPoint, Int32 tapCount)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.OnTap(GestureDetector gestureDetector)
   at Syncfusion.Maui.Core.Internals.GestureDetector.UITapGestureExt.<>c__DisplayClass1_0.<.ctor>b__0()
   at UIKit.UIGestureRecognizer.ParameterlessDispatch.Activated() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIGestureRecognizer.cs:line 107
--- End of stack trace from previous location ---
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2594
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 60
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at MauiMopupsSample.Program.Main(String[] args) in /Users/drasticactions/Developer/Work/ImageEditor-Mopup-Issue/MauiMopupsSample/MauiMopupsSample/MauiMopupsSample/Platforms/iOS/Program.cs:line 13

The important parts are

System.InvalidOperationException: MauiContext should have been set on parent.

and

Syncfusion.Maui.Core.Internals.SfToolbar.Syncfusion.Maui.Core.Internals.IToolbar.InvokeTappedEvent(SfToolbarItem toolbarItem, SfToolbarItem previousToolbarItem)

IMO, this seems like a Syncfusion issue. I would direct this to them first, as I think that's the issue's root. If it is MAUI, they can circle back.

@PureWeen @mattleibow what do you all think?

Yea, the error here is that a view is being removed from a layout that is no longer connected.

We do get the index as part of the remove command

image

so, in theory we could use the index vs the platform view to remove the view, but I do worry this just moves the exception down the pipeline. Because there shouldn't really be a path like this triggering.