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

.NET 9 iOS crashing on device in release mode at System.Threading.Tasks.Task.RunContinuations #28197

Open
pme442 opened this issue Mar 5, 2025 · 2 comments
Labels
area-controls-listview ListView and TableView migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/iOS 🍎 t/bug Something isn't working

Comments

@pme442
Copy link

pme442 commented Mar 5, 2025

Description

I have a large app that I've converted from Xamarin Forms to MAUI.
It's actually too large to be able to create a reproduction.
It has a lot of ListViews that use DataTemplateSelectors. Each data template is rather complex -- nested grids containing a lot of controls and a lot of bindings.
After about 2 to 3 hours of constant use, the app crashes. I also notice that 15 to 30 minutes before it crashes, performance starts to degrade (scrolling through ListView is less smooth, the UI updates slower, etc.)
It hits the AppDomain.CurrentDomain.UnhandledException event and logs the following to my error log:

EXCEPTION: Arg_InvalidCastException
STACK TRACE: at System.Threading.Tasks.Task.RunContinuations(Object ) at System.Threading.Tasks.Task.FinishStageThree() at System.Threading.Tasks.Task.FinishStageTwo() at System.Threading.Tasks.Task.Finish(Boolean ) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread ) at System.Threading.Tasks.Task.ExecuteEntryUnsafe(Thread ) at System.Threading.Tasks.Task.ExecuteFromThreadPool(Thread ) at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread ) at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

This is all that I get, so I have no idea where this is coming from in my code. It never gets caught in a try/catch block.

This does not happen in the Xamarin.Forms version of the app.

Does anyone have an idea of what this error may be a symptom of? Like a memory issue or too many background tasks running?
Is there something that fundamentally changed from Xamarin to Maui in regard to awaiting tasks?
I do a lot of awaiting "heavy processing" functions that are reading from/writing to a sqlite database and then switching back to the main thread to update the UI.

Any thoughts are greatly appreciated.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

No response

Affected platforms

iOS

Affected platform versions

iOS 15, iOS 16, iOS 17, iOS 18

Did you find any workaround?

No

Relevant log output

@pme442 pme442 added the t/bug Something isn't working label Mar 5, 2025
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@tj-devel709 tj-devel709 added migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/iOS 🍎 area-controls-listview ListView and TableView labels Mar 6, 2025
@tj-devel709
Copy link
Member

Hi @pme442, yeah this sounds like a memory issue to me. In Maui, CollectionView is the preferred layout over ListView and has better performance with its built-in native virtualization. If possible, we recommend using CollectionViews.

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/?view=net-maui-9.0#collectionview-and-listview-differences

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 migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants