xamarin / Xamarin.Forms

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

[Bug] [iOS] Clearing ObservableCollection causes NullReferenceException #13910

Closed Janek91 closed 3 years ago

Janek91 commented 3 years ago

Description

Clear of ObservableCollection with some items binded to CollectionView causes NullReferenceException at: https://github.com/xamarin/Xamarin.Forms/blob/a10c2c6218e592bc6896f0fcbd51ae34e1f4d9dc/Xamarin.Forms.Platform.iOS/CollectionView/ObservableItemsSource.cs#L148

System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Reload () [0x00025] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:148 
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x0005a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:132 
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x0002d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:108 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.
framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
  at MvvmCross.ViewModels.MvxObservableCollection`1[T].<>n__0 (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) <0x110541000 + 0x0005a> in <03f32c17c8e741219cee9c3d186bfa64>:0 
  at MvvmCross.ViewModels.MvxObservableCollection`1+<>c__DisplayClass7_0[T].<OnCollectionChanged>b__0 () [0x00000] in /_/MvvmCross/ViewModels/MvxObservableCollection.cs:72 
  at MvvmCross.Base.MvxMainThreadAsyncDispatcher+<>c__DisplayClass0_0.<ExecuteOnMainThreadAsync>b__0 () [0x00000] in /_/MvvmCross/Base/MvxMainThreadAsyncDispatcher.cs:16 
  at MvvmCross.Base.MvxMainThreadAsyncDispatcher+<>c__DisplayClass1_0.<ExecuteOnMainThreadAsync>b__0 () [0x00011] in /_/MvvmCross/Base/MvxMainThreadAsyncDispatcher.cs:27 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions
/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178 

Steps to Reproduce

  1. Create view with CollectionView and bind ObservableCollection to it
  2. Fill ObservableCollection with items
  3. Clear ObservableCollection

Expected Behavior

CollectionView is presented empty and no exception is thrown

Actual Behavior

CollectionView is presented empty, but exception is thrown

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Professional 2019 Version 16.8.6 VisualStudio.16.Release/16.8.6+31019.35 Microsoft .NET Framework Version 4.8.04084 Installed Version: Professional .ignore 1.2.77 A language service that makes it painless to handle all types of .ignore files such as .gitignore, .tfignore, etc. ASP.NET and Web Tools 2019 16.8.560.26713 ASP.NET and Web Tools 2019 ASP.NET Core Razor Language Services 16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2019 16.8.560.26713 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.8.560.26713 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 16.8.560.26713 Azure Functions and Web Jobs Tools C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Edit Project 1.6.34 An open source Visual Studio extension to add the context menu for editing project/solution file. EditorConfig Language Service 1.17.286 Language service for .editorconfig files. EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. Entity Framework Core Power Tools 2.5 Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu. Error Helper 1.7 Make it easy to copy or search for descriptions in the error list. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. GhostDoc 20.2.20270.0 Generate XML Comments from your code, maintain clean and up-to-date documentation, produce help documentation in multiple formats, use intelligent source code Spell Checker in Visual Studio. IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info JetBrains ReSharper 2020.3.3 Build 203.0.20210128.162058 JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2021 JetBrains, Inc. Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1 Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. 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 Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Mono Debugging for Visual Studio 16.8.43 (00471f8) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 5.8.1 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ OzCodePackage Extension 1.0 OzCodePackage Visual Studio Extension Detailed Info ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Rapid XAML Analysis 0.11.5 Tools to accelerate XAML app development by providing analysis and code fixes. Rapid XAML Editor Extras 0.11.5 Tools to accelerate XAML app development by providing additional features to the Visual Studio editor. Rapid XAML Generation 0.11.5 Tools to accelerate XAML app development by generating XAML. Rapid XAML Roslyn Analyzers 0.11.5 Roslyn analyzers to help with XAML development. Rapid XAML Templates 0.11.1 Project and item templates to help with XAML development. Rapid XAML Toolkit 0.11.5 Tools to accelerate XAML app development. This extension holds references and functionality used by the other Rapid XAML extensions. SlowCheetah - XML config transforms 1.0 This package enables you to transform your app.config or any other XML file based on the build configuration. It also adds additional tooling to help you create XML transforms. SQL Server Data Tools 16.0.62102.01130 Microsoft SQL Server Data Tools String Resource Visualizer 1.6 View the text of string resources (.resx) inline when they're used in code. StylerPackage Extension 1.0 StylerPackage Visual Stuido Extension Detailed Info TypeScript Tools 16.0.21016.2001 TypeScript Tools for Microsoft Visual Studio Viasfora 4.3.195 Add color to your Visual Studio editor! Visual Basic Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd Microsoft Visual F# Tools Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSColorOutput 2.73 Color output for build and debug windows - https://mike-ward.net/vscoloroutput WakaTime 1.0 Xamarin 16.8.000.262 (d16-8@4d60f9c) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.8.0.507 (remotes/origin/d16-8@e87b24884) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.8.112 (86385a3) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.1.0.26 (d16-8/a36ce73) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc Xamarin.iOS and Xamarin.Mac SDK 14.10.0.4 (5a05865f6) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

Screenshots

Reproduction Link

Workaround

None

PureWeen commented 3 years ago

@Janek91 can you attach a small project reproducing the issue please?

Redth commented 3 years ago

Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!