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

[regression/8.0.0] MAUI crashing on CarouselView render/remove, flyout menu #17396

Closed
npostma opened this issue Sep 15, 2023 · 13 comments · Fixed by #17505
Closed

[regression/8.0.0] MAUI crashing on CarouselView render/remove, flyout menu #17396

npostma opened this issue Sep 15, 2023 · 13 comments · Fixed by #17505
Assignees
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! high It doesn't work at all, crashes or has a big impact. migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 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

@npostma
Copy link

npostma commented Sep 15, 2023

Description

I am currently in the process of porting my app to MAUI in .NET 8. This decision was primarily influenced by the fact that I've noticed several critical bug fixes in .NET 8 that have not been addressed or backported to .NET 7. However, despite a relatively smooth compilation process without any major issues, I've encountered significant challenges with app stability.

On iOS, the app crashes during the boot process, and on Android, it crashes when attempting to render a carousel. Additionally, when removing the carousel from the view, I encounter another crash when opening the flyout menu by clicking on the hamburger icon. This situation is quite perplexing, especially since the app was running smoothly without any crashes on the .NET 7 version.

I've attempted to investigate the root cause of these issues, but the callstack doesn't provide any information related to my project files; it only references framework files. My suspicion is that there might be an issue with the binding between views and view models or possibly with a custom control or helper within the application. Regrettably, I lack sufficient information to pinpoint the exact problem.

In summary, I'm actively working to resolve these issues and ensure a stable performance for my app in MAUI with .NET 8, but I'm currently faced with a lack of concrete clues regarding the source of the crashes.

Error (very generic, something needs to be initialized but its probably null)

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Callstack

 	0xFFFFFFFFFFFFFFFF in Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception	C#
 	0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:13,5	C#
 	0x20 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLI_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:181,26	C#
 	0xCB in Microsoft.Maui.Controls.VisualStateManager.VisualStateGroupsPropertyChanged at D:\a\_work\1\s\src\Controls\src\Core\VisualStateManager.cs:49,4	C#
 	0xB0 in Microsoft.Maui.Controls.BindableObject.ClearValueCore at D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:139,5	C#
 	0x58 in Microsoft.Maui.Controls.BindableObject.ClearValue at D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:103,4	C#
 	0x59 in Microsoft.Maui.Controls.Setter.UnApply at D:\a\_work\1\s\src\Controls\src\Core\Setter.cs:100,4	C#
 	0x4E in Microsoft.Maui.Controls.Style.UnApplyCore at D:\a\_work\1\s\src\Controls\src\Core\Style.cs:191,5	C#
 	0x13 in Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.UnApply at D:\a\_work\1\s\src\Controls\src\Core\Style.cs:115,4	C#
 	0x8D in Microsoft.Maui.Controls.MergedStyle.SetStyle at D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:193,6	C#
 	0xE in Microsoft.Maui.Controls.MergedStyle.set_ClassStyles at D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:87,10	C#
 	0x1D in Microsoft.Maui.Controls.MergedStyle.OnClassStyleChanged at D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:126,4	C#
 	0x1 in Microsoft.Maui.Controls.MergedStyle.<set_StyleClass>b__13_0 at D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:70,59	C#
 	0x18A in Microsoft.Maui.Controls.BindableObject.SetValueActual at D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:611,5	C#
 	0x162 in Microsoft.Maui.Controls.BindableObject.SetValueCore at D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:539,5	C#
 	0x6 in Microsoft.Maui.Controls.Element.OnResourceChanged at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:815,7	C#
 	0x11A in Microsoft.Maui.Controls.Element.OnResourcesChanged at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:671,6	C#
 	0x10D in Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1436,5	C#
 	0x13F in Microsoft.Maui.Controls.Element.SetParent at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:355,5	C#
 	0x2 in Microsoft.Maui.Controls.Element.OnChildAdded at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:525,4	C#
 	0x2 in Microsoft.Maui.Controls.ShellItem.OnChildAdded at D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellItem.cs:252,4	C#
 	0x18 in Microsoft.Maui.Controls.Element.AddLogicalChild at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:224,4	C#
 	0x97 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRecyclerAdapter.ElementViewHolder.set_Element at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRecyclerAdapter.cs:287,8	C#
 	0x30 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRecyclerAdapter.OnBindViewHolder at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRecyclerAdapter.cs:110,4	C#
 	0x12 in AndroidX.RecyclerView.Widget.RecyclerView.Adapter.n_OnBindViewHolder_Landroidx_recyclerview_widget_RecyclerView_ViewHolder_I at C:\a\_work\1\s\generated\androidx.recyclerview.recyclerview\obj\Release\net6.0-android\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:581,5	C#
 	0xB in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLI_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:180,5	C#
 	0xF in Java.Interop.JniNativeMethods.CallNonvirtualVoidMethodA at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:18296,4	C#
 	0x73 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20825,4	C#
 	0x78 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:75,7	C#
 	0x80 in AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.OnLayout at C:\a\_work\1\s\generated\androidx.coordinatorlayout.coordinatorlayout\obj\Release\net6.0-android\generated\src\AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.cs:2704,5	C#
 	0x19 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutLayout.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutLayout.cs:34,4	C#
 	0x10 in AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.n_OnLayout_ZIIII at C:\a\_work\1\s\generated\androidx.coordinatorlayout.coordinatorlayout\obj\Release\net6.0-android\generated\src\AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.cs:2688,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:444,5	C#

I am using the latest MAUI on Visual Studio 2022 community Preview

Steps to Reproduce

I have no idea, because its a big app being ported from xamarin -> maui .net7 (many layout issues, memory stream issues, etc) -> maui .net8. And i am trying to gather as much information possible to figure this out.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI, Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Not yet

Relevant log output

**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

[EGL_emulation] app_time_stats: avg=16.47ms min=3.87ms max=25.14ms count=61
[EGL_emulation] app_time_stats: avg=16.52ms min=1.95ms max=36.95ms count=60
[EGL_emulation] app_time_stats: avg=3.09ms min=2.46ms max=3.94ms count=61
[EGL_emulation] app_time_stats: avg=3.21ms min=1.29ms max=4.57ms count=60
[EGL_emulation] app_time_stats: avg=3.20ms min=2.67ms max=3.96ms count=61
[EGL_emulation] app_time_stats: avg=3.14ms min=2.41ms max=4.60ms count=61
[libc] Requested dump for tid 28225 (me.activeidmaui)
Thread finished: <Thread Pool> #5
Thread finished: <Thread Pool> #11
Thread finished: <Thread Pool> #2
Thread finished: <Thread Pool> #10
Thread started: <Thread Pool> #12
**System.NullReferenceException:** 'Loading...'

The thread 0x5 has exited with code 0 (0x0).
The thread 0xb has exited with code 0 (0x0).
The thread 0x2 has exited with code 0 (0x0).
The thread 0xa has exited with code 0 (0x0).
@npostma npostma added the t/bug Something isn't working label Sep 15, 2023
@samhouts samhouts added platform/android 🤖 platform/iOS 🍎 area-controls-collectionview CollectionView, CarouselView, IndicatorView high It doesn't work at all, crashes or has a big impact. potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 15, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Sep 15, 2023
@samhouts samhouts changed the title [.NET8] MAUI [.NET8] MAUI crashing on CarouselView render/remove, flyout menu Sep 15, 2023
@npostma
Copy link
Author

npostma commented Sep 17, 2023

I have additional information concerning the iOS crash, and it appears to be similar to the Android crash. Unfortunately, it doesn't trigger a breakpoint, so I don't have access to the call stack in Visual Studio. However, I have included some logging in my console output (see below).

This crash occurs immediately after the splash screen when the landing page is being loaded. The landing page is a straightforward one, featuring a grid, an image, and two buttons.

To clarify, I'm not certain whether the iOS and Android issues are identical. They do seem related, but if they are distinct problems, they may need to be addressed separately. If there's any way I can assist in resolving these issues, please don't hesitate to reach out to me!

2023-09-17 09:51:47.273918+0200 ActiveID_MAUI[33291:292965] System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.VisualStateManager.VisualStateGroupsPropertyChanged(BindableObject bindable, Object oldValue, Object newValue)
2023-09-17 09:51:47.274049+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.BindableObject.ClearValueCore(BindableProperty property, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, SetterSpecificity specificity)
2023-09-17 09:51:47.274209+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.Style.UnApplyCore(BindableObject bindable, Style basedOn)
   at Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.UnApply(BindableObject bindable)
2023-09-17 09:51:47.274326+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList`1 classStyles, IStyle style)
   at Microsoft.Maui.Controls.MergedStyle.set_ClassStyles(IList`1 value)
   at Microsoft.Maui.Controls.MergedStyle.OnClassStyleChanged()
2023-09-17 09:51:47.274423+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.MergedStyle.<set_StyleClass>b__13_0(BindableObject bindable, Object oldvalue, Object newvalue)
2023-09-17 09:51:47.274526+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
2023-09-17 09:51:47.274635+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.Element.OnResourceChanged(BindableProperty property, Object value, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable`1 values)
2023-09-17 09:51:47.274734+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable`1 values)
   at Microsoft.Maui.Controls.Element.SetParent(Element value)
   at Microsoft.Maui.Controls.Element.OnChildAdded(Element child)
   at Microsoft.Maui.Controls.ShellItem.OnChildAdded(Element child)
2023-09-17 09:51:47.274823+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.Element.AddLogicalChild(Element element)
   at Microsoft.Maui.Controls.Platform.Compatibility.UIContainerCell..ctor(String cellId, View view, Shell shell, Object context)
2023-09-17 09:51:47.274909+0200 ActiveID_MAUI[33291:292965]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellTableViewSource.GetCell(UITableView tableView, NSIndexPath indexPath)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
2023-09-17 09:51:47.274986+0200 ActiveID_MAUI[33291:292965]    at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at ActiveID_MAUI.Program.Main(String[] args) in C:\src\sc_mc\ActiveID_MAUI\ActiveID_MAUI\Platforms\iOS\Program.cs:line 14
2023-09-17 09:51:49.776805+0200 ActiveID_MAUI[33291:292965] [client] Timed out waiting for the exit barrier block. activeSendTransactions=0
Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown.
Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown.

@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Sep 19, 2023
@samhouts samhouts changed the title [.NET8] MAUI crashing on CarouselView render/remove, flyout menu [regression/8.0.0] MAUI crashing on CarouselView render/remove, flyout menu Sep 19, 2023
@StephaneDelcroix
Copy link
Contributor

could you share a snippet of code/xaml triggering the issue ?

@StephaneDelcroix
Copy link
Contributor

the stack trace point to 'newValue' being null in VisualStateGroupsPropertyChanged (as it comes after a ClearValue). What I don't get is that this code was barely changed, and VSGPropertyChanged always assumed newValue wasn't null. I'm going to propose a change to check for null value, and hope for the best as we don't have a small repro to test on

StephaneDelcroix added a commit that referenced this issue Sep 20, 2023
@PureWeen
Copy link
Member

PureWeen commented Sep 20, 2023

@npostma can you share your Shell.xaml file and any related styles/app.xaml/styles.xaml/colors.xaml? Do you modify shell at all during load?

@npostma
Copy link
Author

npostma commented Sep 20, 2023

@StephaneDelcroix newValue is not something in my code. The stacktrace and break point do not break in my code but in 'external code' So its very (if not impossible?) for me to see what the source of this issue is. If there is a visual studio setting that could provide more info let me know. I there a way how we could debug XAML (Wrong bindings and such)?

Also, is there a way for me i can validate/test your fix?

All i can see is this:

image

@PureWeen First Do you modify shell at all during load not really, i have one menu item that has an IsVisible binding. It would be nice to know what element is faulty or the name of the binding. So i could some step by step debugging (removing code)

I will share a redacted version of my AppShell.xaml and colors.xaml. Styles is quite big and not sure what i can share from that file.

Colors.xaml

<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Color x:Key="CompanyBlack">#000000</Color>
    <Color x:Key="CompanyWhite">#ffffff</Color>

    <Color x:Key="PrimaryBackground">#000000</Color>
    <Color x:Key="PrimaryBackgroundAccent">#000000</Color>
    <Color x:Key="SecondaryBackground">#000000</Color>
    <Color x:Key="PrimaryForeground">#000000</Color>
    <Color x:Key="AccentBackground">#000000</Color>
    <Color x:Key="SeparatorBackground">#000000</Color>

    <Color x:Key="PrimaryText">#000000</Color>
    <Color x:Key="SecondaryText">#000000</Color>
    <Color x:Key="HeaderText">#000000</Color>
    <Color x:Key="SecondaryFaintedText">#000000</Color>
    <Color x:Key="SecondaryLightenText">#000000</Color>
    <Color x:Key="AccentText">#000000</Color>
    <Color x:Key="AccentTextDisabled">#00000011</Color>
    <Color x:Key="ErrorText">#000000</Color>
    <Color x:Key="ErrorBackground">#000000</Color>
    <Color x:Key="ErrorTextDisabled">#000000</Color>
    <Color x:Key="WarningText">#000000</Color>
    <Color x:Key="WarningTextBackground">#000000</Color>
    <Color x:Key="WarningTextDisabled">#000000</Color>
    <Color x:Key="SuccessText">#000000</Color>
    <Color x:Key="SuccessTextBackground">#000000</Color>
    <Color x:Key="SuccessTextDisabled">#00000011</Color>
    <Color x:Key="Button">#000000</Color>
    <Color x:Key="Active">#000000</Color>
    <Color x:Key="Inactive">#000000</Color>
    <Color x:Key="ButtonDisabled">#000000</Color>

</ResourceDictionary>

FlyoutHeaderTemplate

<?xml version="1.0" encoding="utf-8" ?>
<StackLayout 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:NAMESPACE"
    x:Class="NAMESPACE.Views.Template.FlyoutHeaderTemplate"
    xmlns:resources="clr-namespace:NAMESPACE.Resources"
    Padding="0"
    Margin="0"
    HeightRequest="200"
    MaximumHeightRequest="200"
    VerticalOptions="StartAndExpand"
>
    <StackLayout 
        Style="{DynamicResource SOMESTYLE}"
        x:Name="CompanyHeader"
        
    >
        <Image 
            x:Name="CompanyLogo"
            Style="{DynamicResource SOMESTYLE}"
        />
    </StackLayout>

    <Label 
        Text="{x:Static resources:Localization.SOMELABEL}" 
        Style="{DynamicResource SOMESTYLE}"
        x:Name="LABELA"
    />
    <Label 
        Text="{x:Static resources:Localization.SOMELABEL}" 
        Style="{DynamicResource SOMESTYLE}"
        x:Name="LABELB"
    />
</StackLayout>

@PureWeen
Copy link
Member

@npostma

i have one menu item that has an IsVisible binding. It would be nice to know what element is faulty or the name of the binding. So i could some step by step debugging (removing code)

if you remove this binding do you still get a crash?

@npostma
Copy link
Author

npostma commented Sep 21, 2023

@PureWeen in short: yes, it stil crashes after removing the IsVisible binding.

For android: Opening the app works. After login the page with the carousel is trying to load -> crash.
Then -> Removing the carousel in its whole from the view, only a grid is left, app does not crash. Then opening the flyout menu -> crash.

For iOS: Loading the app -> crash.

I looks like the same issue (same stack trace) but i do not think its one thing in my code.

Console output after removing the IsVisible from the AppShell.xaml. After pressing 3x continue on the crash:

**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

The thread 0x4 has exited with code 0 (0x0).
The thread 0xd has exited with code 0 (0x0).
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

The thread 0xb has exited with code 0 (0x0).
Thread finished: <Thread Pool> #4
Thread finished: <Thread Pool> #13
Thread finished: <Thread Pool> #11
Thread started: .NET TP Worker #14
Thread started: <Thread Pool> #15
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

[DOTNET] exception: Exception: CurrentDomainOnUnhandledException
[DOTNET] 	Source: 
[DOTNET] 	TargetSite: 
[DOTNET] 	StackTrace: Inner Exception: Object reference not set to an instance of an object.
[0:] exception: Exception: CurrentDomainOnUnhandledException
	Source: 
	TargetSite: 
	StackTrace: Inner Exception: Object reference not set to an instance of an object.
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]    at Microsoft.Maui.Controls.VisualStateManager.VisualStateGroupsPropertyChanged(BindableObject bindable, Object oldValue, Object newValue) in D:\a\_work\1\s\src\Controls\src\Core\VisualStateManager.cs:line 49
[mono-rt]    at Microsoft.Maui.Controls.BindableObject.ClearValueCore(BindableProperty property, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 139
[mono-rt]    at Microsoft.Maui.Controls.BindableObject.ClearValue(BindableProperty property, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 103
[mono-rt]    at Microsoft.Maui.Controls.Setter.UnApply(BindableObject target, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\Setter.cs:line 100
[mono-rt]    at Microsoft.Maui.Controls.Style.UnApplyCore(BindableObject bindable, Style basedOn) in D:\a\_work\1\s\src\Controls\src\Core\Style.cs:line 191
[mono-rt]    at Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.UnApply(BindableObject bindable) in D:\a\_work\1\s\src\Controls\src\Core\Style.cs:line 115
[mono-rt]    at Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList`1 classStyles, IStyle style) in D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:line 193
[mono-rt]    at Microsoft.Maui.Controls.MergedStyle.set_ClassStyles(IList`1 value) in D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:line 87
[mono-rt]    at Microsoft.Maui.Controls.MergedStyle.OnClassStyleChanged() in D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:line 126
[mono-rt]    at Microsoft.Maui.Controls.MergedStyle.<set_StyleClass>b__13_0(BindableObject bindable, Object oldvalue, Object newvalue) in D:\a\_work\1\s\src\Controls\src\Core\MergedStyle.cs:line 70
[mono-rt]    at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 611
[mono-rt]    at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 539
[mono-rt]    at Microsoft.Maui.Controls.Element.OnResourceChanged(BindableProperty property, Object value, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 815
[mono-rt]    at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable`1 values) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 671
[mono-rt]    at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable`1 values) in D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:line 1436
[mono-rt]    at Microsoft.Maui.Controls.Element.SetParent(Element value) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 355
[mono-rt]    at Microsoft.Maui.Controls.Element.OnChildAdded(Element child) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 525
[mono-rt]    at Microsoft.Maui.Controls.ShellItem.OnChildAdded(Element child) in D:\a\_work\1\s\src\Controls\src\Core\Shell\ShellItem.cs:line 252
[mono-rt]    at Microsoft.Maui.Controls.Element.AddLogicalChild(Element element) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 224
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRecyclerAdapter.ElementViewHolder.set_Element(Element value) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRecyclerAdapter.cs:line 287
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRecyclerAdapter.OnBindViewHolder(ViewHolder holder, Int32 position) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRecyclerAdapter.cs:line 110
[mono-rt]    at AndroidX.RecyclerView.Widget.RecyclerView.Adapter.n_OnBindViewHolder_Landroidx_recyclerview_widget_RecyclerView_ViewHolder_I(IntPtr jnienv, IntPtr native__this, IntPtr native_holder, Int32 position) in C:\a\_work\1\s\generated\androidx.recyclerview.recyclerview\obj\Release
et6.0-android\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:line 581
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLI_V(_JniMarshal_PPLI_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, Int32 p1) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 180
[mono-rt]    at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 20825
[mono-rt]    at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 75
[mono-rt]    at AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.OnLayout(Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) in C:\a\_work\1\s\generated\androidx.coordinatorlayout.coordinatorlayout\obj\Release
et6.0-android\generated\src\AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.cs:line 2704
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutLayout.OnLayout(Boolean changed, Int32 left, Int32 top, Int32 right, Int32 bottom) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutLayout.cs:line 34
[mono-rt]    at AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) in C:\a\_work\1\s\generated\androidx.coordinatorlayout.coordinatorlayout\obj\Release
et6.0-android\generated\src\AndroidX.CoordinatorLayout.Widget.CoordinatorLayout.cs:line 2688
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V(_JniMarshal_PPZIIII_V callback, IntPtr jnienv, IntPtr klazz, Boolean p0, Int32 p1, Int32 p2, Int32 p3, Int32 p4) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 444
[HostConnection] createUnique: call
[HostConnection] HostConnection::get() New Host Connection established 0x767da7026490, tid 6537
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 

@npostma
Copy link
Author

npostma commented Sep 22, 2023

@PureWeen @StephaneDelcroix I did some debugging by removing a lot of code en step by step re-adding the xml unit it crashes. My conclusions is that a lot of elements (95%) with a binding make the app crash. A simple example of this:

In the view i have an element:

<Label Grid.Row="1"
    Text="{Binding Name}"
    HorizontalOptions="CenterAndExpand"
    VerticalOptions="Center" 
    Style="{DynamicResource SubTitle}"
/>

if i remove the {Binding Name} and change it to a default string, it works (the app wont crash). In the viewmodel i have this:

public string Name=> activeUser?.Name ?? "";

So if there is a activeUser, use the name property, else use empty string. Changing this to public string Name=> ""; fixes the specific crash.

Then i tested to keep activeUser null. No crash. So when activeUser transfers from null to a user object i get this error.

Does this information help? This code works fine in Xamarin, Maui .NET6 and .NET7

[EDIT :: ADDED]

Another simpler example @PureWeen @StephaneDelcroix.

I have this element:

<Label 
    FontFamily="LaSolid"
    IsVisible="{Binding Verified, Converter={Converters:InverseBoolConverter}}"
    Text="&#xf0e0;"
    TextColor="{DynamicResource MyColor}"
    HorizontalOptions="Center"
    VerticalOptions="Center" 
    Style="{DynamicResource SubTitle}"
/>

This crashes. Do i remove IsVisible="{Binding Verified, Converter={Converters:InverseBoolConverter}}" it wont crash. Removing only , Converter={Converters:InverseBoolConverter} did not fix it. So it is the binding Verified. Code behind the Verified in the viewmodel:

/// <summary>
/// Docs
/// </summary>
private bool verified = false;

public bool Verified
{
    get => verified;
    set
    {
        if (value == verified)
        {
            return;
        }

        verified = value;
        OnPropertyChanged(nameof(Verified));
    }
}

protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
    PropertyChangedEventHandler changed = PropertyChanged;
    if (changed == null)
    {
        return;
    }

    changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

So this is quite simple code that crashes. I think there is a new way of doing this binding stuff in MAUI? But first i need the app to run before i can update/actualize the code to the new standards.

@PureWeen
Copy link
Member

Where do these labels live?

<Label Grid.Row="1"
    Text="{Binding Name}"
    HorizontalOptions="CenterAndExpand"
    VerticalOptions="Center" 
    Style="{DynamicResource SubTitle}"
/>

are they part of your flyout item templates?

@npostma
Copy link
Author

npostma commented Sep 23, 2023

@PureWeen Not applicable to the example provided above. These labels are situated within an extended class derived from ContentView. This ContentView is loaded within the constructor, subsequent to the InitializeComponent() call, within a class that itself extends a ContentPage.

Should I remove all of this code, the issue transfers to the flyout menu. Furthermore, I encounter this crash when using a source binding for an image within a simple ContentPage, indicating that this specific crash can manifest across various scenarios.

Container code of the content page

<Grid x:Name="viewContainer" Margin="0" Padding="0" ColumnSpacing="0" RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
</Grid>

Constructor code from the ContentPage:

InitializeComponent();

MyView = new CardsCarouselIOS();
MyView .BindingContext = BindingContext;
viewContainer.Add(MyView);

image

@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Sep 24, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in MAUI SDK Ongoing Sep 25, 2023
PureWeen pushed a commit that referenced this issue Sep 25, 2023
@npostma
Copy link
Author

npostma commented Oct 5, 2023

I can conclude that this is indeed fixed. I do not experience the crash in the main or in the net/8.0 branch! Tested for android.

@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Oct 10, 2023
@npostma
Copy link
Author

npostma commented Oct 18, 2023

Also fixed it for iOS, thanks!

@ghost
Copy link

ghost commented Oct 18, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! high It doesn't work at all, crashes or has a big impact. migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 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

Successfully merging a pull request may close this issue.

4 participants