dotnet / maui

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

ListView with IsGroupingEnabled = true throws System.NullReferenceException in Android outside of single project structure #19845

Open nau-dwb opened 9 months ago

nau-dwb commented 9 months ago

Description

If we have a MAUI page with a ListView that has grouping enabled invoked in a stand alone .NET Android application (not part of the single project structure where MAUI\Android\iOS code is all together) then the page throws System.NullReferenceException: 'Object reference not set to an instance of an object.' when loading.

This does NOT happen in Android if using the single project structure.

It does NOT happen in iOS whether it's standalone or single project structure.

It does NOT happen if not using grouping.

We're trying to migrate our Xamarin application to .NET 7 and MAUI. Our Xamarin Android and Xamarin iOS applications are their own project and all our Xamarin Forms code is in a .NET Standard project that the Android and iOS projects reference. We need to keep this same structure going forward (separate .NET7 Android and .NET7 iOS projects referencing a shared project containing the MAUI code targeting .NET android and iOS)

Steps to Reproduce

  1. Create a new .NET Android application using MAUI embedded - this needs to be a standalone Android app and not Android code under a single project structure MAUI project.
  2. Create a MAUI page that has a ListView with IsGroupingEnabled set to true and other relevant grouping bindings set.
  3. Navigate to this page

Expected: List displays formatted to support grouping

Actual: NullReferenceException thrown.

In the provided repro, run the code in simple-android-embedded to repro this exception. Running the code in simple-maui-embedded will demonstrate that this works correctly in Android under the single project structure.

Link to public reproduction project repository

https://github.com/nau-dwb/maui-embedded-use-issues/tree/main

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 26+ with .NET 7

Did you find any workaround?

No real workarounds. As noted, this works fine if using the single project structure but we cannot switch to a single project structure at this time.

The only workaround to unblock will be to not use grouping in the list if running on Android.

Relevant log output

0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.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:12,5 C#
    0x26 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:430,26  C#
    0x39 in Android.Runtime.DynamicMethodNameCounter.5  C#
    0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a    C#
    0x74 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:12320,4    C#
    0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6    C#
    0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5   C#
    0x1F in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\VisualElementRenderer.cs:54,6    C#
    0x8 in Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ListViewRenderer.cs:298,4   C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,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:429,5   C#
    0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a    C#
    0x74 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:12320,4    C#
    0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6    C#
    0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5   C#
    0xD4 in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at D:\a\_work\1\s\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:133,4  C#
    0x2 in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.Microsoft.Maui.IViewHandler.PlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\VisualElementRenderer.cs:230,4 C#
    0x1F in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:119,4 C#
    0x2 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:111,4 C#
    0x74 in Microsoft.Maui.Layouts.GridLayoutManager.ArrangeChildren at D:\a\_work\1\s\src\Core\src\Layouts\GridLayoutManager.cs:47,5   C#
    0x24 in Microsoft.Maui.Controls.AndExpandLayoutManager.ArrangeChildren at D:\a\_work\1\s\src\Controls\src\Core\Layout\AndExpandLayoutManager.cs:37,4    C#
    0x7 in Microsoft.Maui.Controls.StackLayoutManager.ArrangeChildren at D:\a\_work\1\s\src\Controls\src\Core\Layout\StackLayoutManager.cs:36,4 C#
    0x7 in Microsoft.Maui.Controls.Layout.CrossPlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\Layout\Layout.cs:287,4   C#
    0x2A in Microsoft.Maui.Platform.LayoutViewGroup.OnLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\LayoutViewGroup.cs:96,4    C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,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:429,5   C#
    0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a    C#
    0x74 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:12320,4    C#
    0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6    C#
    0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5   C#
    0xD4 in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at D:\a\_work\1\s\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:133,4  C#
    0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutViewGroup>.PlatformArrange at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.Android.cs:15,4  C#
    0x1F in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:119,4 C#
    0x2 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:111,4 C#
    0x7B in Microsoft.Maui.Controls.Compatibility.Layout.LayoutChildIntoBoundingRegion at D:\a\_work\1\s\src\Controls\src\Core\Layout.cs:157,5  C#
    0x110 in Microsoft.Maui.Controls.Page.LayoutChildren at D:\a\_work\1\s\src\Controls\src\Core\Page.cs:322,6  C#
    0xCF in Microsoft.Maui.Controls.Page.UpdateChildrenLayout at D:\a\_work\1\s\src\Controls\src\Core\Page.cs:410,4 C#
    0x10 in Microsoft.Maui.Controls.Page.OnSizeAllocated at D:\a\_work\1\s\src\Controls\src\Core\Page.cs:389,4  C#
    0x3 in Microsoft.Maui.Controls.VisualElement.SizeAllocated at D:\a\_work\1\s\src\Controls\src\Core\VisualElement.cs:1175,64 C#
    0x4E in Microsoft.Maui.Controls.VisualElement.UpdateBoundsComponents at D:\a\_work\1\s\src\Controls\src\Core\VisualElement.cs:1495,4    C#
    0x11 in Microsoft.Maui.Controls.VisualElement.set_Frame at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:28,5    C#
    0x2 in Microsoft.Maui.Controls.ContentPage.Microsoft.Maui.IContentView.CrossPlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\ContentPage.Impl.cs:34,4    C#
    0x22 in Microsoft.Maui.Platform.ContentViewGroup.OnLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\ContentViewGroup.cs:92,4  C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,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:429,5   C#
Zhanglirong-Winnie commented 5 months ago

Verified this issue with Visual Studio 17.10.0 Preview 5(.NET8 &.NET7). Can repro on android platform with sample project. .NET7: Throws System.NullReferenceException. image .NET8: App crashes on the emulator.

PureWeen commented 5 months ago

/similarissues

github-actions[bot] commented 5 months 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!

Open similar issues:

Closed similar issues:

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