xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] Crash in CarouselView on Android #14496

Open woolfman007 opened 2 years ago

woolfman007 commented 2 years ago

Description

I’m not sure if it’s my fault, but I cannot see how, so here’s my scenario:

I have a page with one big CarouselView, which is displaying the results of certain filter criteria. On another page, I can set these filter criteria. Whenever I come back the Carousel page, I update its ItemsSource from within the pages OnAppearing() call. And here comes the crash; if the Carousel was empty the last time and gets populated again, it raises an exception saying “‘Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index’”

All that does not happen, if I modify the ItemsSource while staying on the page (e.g. via a command). It only happens when I do it within OnAppearing(). In the PositionChanged event, I can see, that it tries to set the Position to -1 somewhere, that looks like the reason for the crash. And by the way: everything works fine on iOS, the crash happens only in Android.

Seems my attachment is too big, so I put it on GoogleDrive: https://drive.google.com/file/d/1PLAZ7Fvk1hzwWQjpwPks9jnM-loxYeMy/view

Steps to Reproduce

  1. build the attached project
  2. run the Android version (simulator or real device, doesn't matter)
  3. switch between the 2 tabs TWICE; after that, the crash will happen

Expected Behavior

no crash

Actual Behavior

crash via out fo range exception

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Community 2019 Version 16.10.4 VisualStudio.16.Release/16.10.4+31515.178 Microsoft .NET Framework Version 4.8.04084 Installierte Version: Community Visual C++ 2019 00435-60000-00000-AA327 Microsoft Visual C++ 2019 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools Allgemeine Azure-Tools 1.10 Bietet allgemeine Dienste für die Verwendung durch Azure Mobile Services und Microsoft Azure-Tools. ASA Service Provider 1.0 ASP.NET and Web Tools 2019 16.10.526.50910 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2019 16.10.526.50910 Weitere Informationen finden Sie unter https://www.asp.net/. Azure App Service-Tools v3.0.0 16.10.526.50910 Azure App Service-Tools v3.0.0 Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.6.1000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 16.10.526.50910 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C#-Tools 3.10.0-4.21329.37+246ce641f04b67ef017655275d850bf902a8e40f C#-Komponenten, die in der IDE verwendet werden. Abhängig von Ihrem Projekttyp und den zugehörigen Einstellungen kann eine andere Version des Compilers verwendet werden. Erweiterungen der Visual Studio-Containertools 1.0 Hiermit werden Container in Visual Studio angezeigt, verwaltet und diagnostiziert. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Fabric.DiagnosticEvents 1.0 Fabric-Diagnoseereignisse IntelliCode-Erweiterung 1.0 Detaillierte Informationen zur IntelliCode Visual Studio-Erweiterung Microsoft Azure-Tools 2.9 Microsoft Azure-Tools für Microsoft Visual Studio 2019 – v2.9.40423.1 Microsoft Azure HDInsight Azure Node 2.6.1000.0 HDInsight Node under Azure Node Microsoft Azure Hive Query Language Service 2.6.1000.0 Language service for Hive query Microsoft Azure Service Fabric-Tools für Visual Studio 16.10 Microsoft Azure Service Fabric-Tools für Visual Studio Microsoft Azure Stream Analytics Language Service 2.6.1000.0 Language service for Azure Stream Analytics Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node Microsoft Continuous Delivery Tools für Visual Studio 0.4 Die Konfiguration von Azure DevOps-Pipelines von der Visual Studio-IDE aus wird vereinfacht. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++-Assistenten 1.0 Microsoft Visual C++-Assistenten Microsoft Visual Studio-Tools für Container 1.2 Jetzt können Sie Ihre ASP.NET Core-Anwendung in der Zielumgebung entwickeln, ausführen und überprüfen. Drücken Sie F5, um die Anwendung direkt in einem Container mit Debugfunktionen auszuführen, oder STRG+F5 zum Bearbeiten und Aktualisieren Ihrer Anwendung, ohne den Container erneut erstellen zu müssen. Mono Debugging for Visual Studio 16.10.15 (552afdf) Support for debugging Mono processes with Visual Studio. MySQL for Visual Studio 1.2.9 Data design and management tools for MySQL. Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. NuGet-Paket-Manager 5.10.0 NuGet-Paket-Manager in Visual Studio. Weitere Informationen zu NuGet finden Sie unter https://docs.nuget.org/. ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Razor (ASP.NET Core) 16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725 Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 16.0.62106.24090 Microsoft SQL Server Data Tools Testadapter für Boost.Test 1.0 Aktiviert Visual Studio-Testtools mit Komponententests, die für Boost.Test geschrieben wurden. Nutzungsbedingungen und Drittanbieterhinweise stehen im Installationsverzeichnis der Erweiterung zur Verfügung. Testadapter für Google Test 1.0 Ermöglicht die Verwendung von Visual Studio-Testtools mit Komponententests, die für Google Test geschrieben wurden. Die Nutzungsbedingungen und Drittanbieterhinweise stehen im Installationsverzeichnis der Erweiterung zur Verfügung. ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript-Tools 16.0.30429.2002 TypeScript-Tools für Microsoft Visual Studio VC-Paket für Microsoft Visual Studio 1.0 VC-Paket für Microsoft Visual Studio Visual Basic-Tools 3.10.0-4.21329.37+246ce641f04b67ef017655275d850bf902a8e40f Visual Basic-Komponenten, die in der IDE verwendet werden. Abhängig von Ihrem Projekttyp und den zugehörigen Einstellungen kann eine andere Version des Compilers verwendet werden. Visual F# Tools 16.10.0-beta.21262.7+1b23bbeda88ea3cb9be9af777f4c99fa8663df81 Microsoft Visual F# Tools Visual Studio-Tools für CMake 1.0 Visual Studio-Tools für CMake Visual Studio-Tools für Container 1.0 Visual Studio-Tools für Container Visual Studio-Tools für Kubernetes 1.0 Visual Studio-Tools für Kubernetes Visual Studio-Tools für Unity 4.10.3.0 Visual Studio-Tools für Unity Visual Studio Code-Debugadapter-Hostpaket 1.0 Interopebene zum Hosten der Visual Studio Code-Adapter in Visual Studio VisualStudio.DeviceLog 1.0 Informationen zum Paket VisualStudio.Foo 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 16.10.000.234 (d16-10@ecaf29b) Visual Studio-Erweiterung, um Entwicklung für Xamarin.iOS und Xamarin.Android zu ermöglichen. Xamarin Designer 16.10.0.115 (remotes/origin/c750fbf1bde3c720d077f51640fe197c6dac7cbe@c750fbf1b) Visual Studio-Erweiterung zum Aktivieren der Xamarin Designer-Tools in Visual Studio. Xamarin Templates 16.10.5 (355b57a) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.3.0.4 (d16-10/ae14caf) Xamarin.Android Reference Assemblies and MSBuild support. Mono: b4a3858 Java.Interop: xamarin/java.interop/d16-10@f39db25 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.35.4@85460d3 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0 Xamarin.iOS and Xamarin.Mac SDK 14.20.0.24 (c4b89cddb) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

Screenshots

Reproduction Link

https://drive.google.com/file/d/1PLAZ7Fvk1hzwWQjpwPks9jnM-loxYeMy/view

Workaround

jsuarezruiz commented 2 years ago
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:161 
  at System.Collections.Generic.List`1[T].System.Collections.IList.get_Item (System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:188 
  at Xamarin.Forms.Platform.Android.ObservableItemsSource.ElementAt (System.Int32 index) [0x0000f] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ObservableItemsSource.cs:226 
  at Xamarin.Forms.Platform.Android.ObservableItemsSource.GetItem (System.Int32 position) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ObservableItemsSource.cs:62 
  at Xamarin.Forms.Platform.Android.CarouselViewRenderer.SetCurrentItem (System.Int32 carouselPosition) [0x00043] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:504 
  at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdateInitialPosition () [0x00076] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:362 
  at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdateAdapter () [0x00069] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:141 
  at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdateItemsSource () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:151 
  at Xamarin.Forms.Platform.Android.ItemsViewRenderer`3[TItemsView,TAdapter,TItemsViewSource].SetUpNewElement (TItemsView newElement) [0x00053] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ItemsViewRenderer.cs:316 
  at Xamarin.Forms.Platform.Android.CarouselViewRenderer.SetUpNewElement (Xamarin.Forms.ItemsView newElement) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:94 
  at Xamarin.Forms.Platform.Android.ItemsViewRenderer`3[TItemsView,TAdapter,TItemsViewSource].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0004f] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ItemsViewRenderer.cs:104 
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:358 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000b3] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:140 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:351 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:112 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:481 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000e8] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:244 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:131 
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:358 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000b3] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:140 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:351 
  at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:112 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:481 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000e8] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:244 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:131 
  at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, AndroidX.Fragment.App.FragmentManager fragmentManager, Android.Content.Context context) [0x00031] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:404 
  at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:57 
  at Xamarin.Forms.Platform.Android.AppCompat.ShellFragmentContainer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00011] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\ShellFragmentContainer.cs:35 
  at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00021] in D:\a\1\s\generated\androidx.fragment.fragment\obj\Release\monoandroid90\generated\src\AndroidX.Fragment.App.Fragment.cs:1950 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.64(intptr,intptr,intptr,intptr,intptr)