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

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

Open
nau-dwb opened this issue Jan 11, 2024 · 3 comments
Labels
area-controls-listview ListView and TableView 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 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@nau-dwb
Copy link

nau-dwb commented Jan 11, 2024

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#
@nau-dwb nau-dwb added the t/bug Something isn't working label Jan 11, 2024
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Jan 12, 2024
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 29, 2024
@Zhanglirong-Winnie
Copy link

Zhanglirong-Winnie commented Apr 29, 2024

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
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

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.

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 5, 2024
@jsuarezruiz jsuarezruiz added the high It doesn't work at all, crashes or has a big impact. label Jun 5, 2024
@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-listview ListView and TableView 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 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants