dotnet / dotnet/maui

CollectionView with ObservableCollection ItemsSource, sporadic exception causing crash on iOS

Open
#34,261 0 comments 0 reactions 0 assignees View on GitHub
t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I've not experienced this during my testing on my iOS devices but I can see it occurring on iOS devices sporadically in [Sentry.io](http://sentry.io/) (4 times over the last 6 days) but the sample size is low, about 15 active test users, though they are using the application heavily each day. All instances were on iOS 26.2.1.

The application has multiple pages with CollectionViews that have ObservableCollections as item sources. The most typical situation is users scanning barcodes for items they are delivering, and if the barcode matches an item or items, it adds a model per item to the ItemsSource. They are doing this hundreds and thousands of times a day without issue but 4 separate times over 6 days, this exception has occurred and I'm stumped at how to address it and am finding it impossible to replicate.

This must be occurring when the ObservableCollection is either having an item or items added or when the list is cleared simply based on the stack trace. I have verified there is no instance where a null item would be added to these ObservableCollections.

This is a .net 9 Maui app.

Here is the relevant stack trace:

```
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at ref TemplatedCell Dictionary.FindValue(object)()
at bool Dictionary.TryGetValue(object key, out TemplatedCell value)()
at void ItemsViewController.UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)()
at UICollectionViewCell ItemsViewController.GetCell(UICollectionView collectionView, NSIndexPath indexPath)()
at NativeHandle ItemsViewController.__IRegistrarGenericTypeProxy__Microsoft_Maui_Controls_Handlers_Items_ItemsViewController_1___GetCell(IntPtr sel, IntPtr p0, IntPtr p1, IntPtr* exception_gchandle)()
```

### Steps to Reproduce

Unfortunately, I have failed to replicate the issue, as it's incredibly sporadic but happening enough to be a concern as we have not done a full rollout of the app to all our users, yet.

### Link to public reproduction project repository

_No response_

### Version with bug

10.0.10

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

Unknown/Other

### Affected platforms

iOS

### Affected platform versions

so far I have only seen 4 instances all on iOS 26.2.1

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

The stack trace names ItemsViewController.UpdateTemplatedCell and GetCell as entry points; begin by tracing the templated-cell dictionary lookup that receives the null key. There is no reproduction project or test in the report, so done would require a reproducible iOS failure and a verified fix or regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, ios
Domain
mobile
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.