-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Enumerating contacts retrieved by GetAllAsync traps #22957
Comments
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! Closed similar issues:
|
Could you please make a sample showing how you're implementing this code? Seeing "MainThread.BeginInvokeOnMainThread", I think that may be your issue. If you want to interact with the UI thread, you should use MAUI's Dispatcher, something like var contacts = await ContactsManager.Default.GetAllAsync();
await Task.Run(() =>
{
foreach (var contact in contacts)
{
Microsoft.Maui.Controls.Application.Current!.Dispatcher.Dispatch(() => ContactsList.Add(contact));
}
}); Although I'm not sure why you're putting this in a Task only to dispatch back on the UIThread? I think we need more context for what you're doing. |
I'd based it on the example found here: Since it's trapping when beginning the enumeration, it doesn't matter what's inside the foreach. However, I tried your suggestion and it still traps. A simplified example that still traps:
|
I wrote a sample: https://github.com/drasticactions/MauiRepros/tree/main/ContactsTest I can't get it to fail. Can you run this and see if it works for you? This is the Essentials code it's calling,
@rolfbjarne Would you know of other ways to debug this? |
A crash report might give clues: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#crash-reports Also is anything printed in the application output when the ap crashes? |
@drasticactions your code does the same as mine.
|
@drasticactions let me clarify -- your code also traps. |
That's dotnet/runtime#98941, which has been fixed in the latest .NET version. Please make sure you're using the latest .NET (8.0.300) and try again. If it still fails, please provide a binlog (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs). |
Ahhh, okay. That would explain it. @tg2-mygovus Can you upgrade your dotnet? |
That got it!! Thank you :) |
Description
In .NET MAUI (targeting net8.0-ios), the following code aborts (catch doesn't catch):
When trying to iterate over the list of contacts (in the foreach).
what's interesting is I can retrieve one contact with
await ContactsManager.Default.PickContactAsync()
I've only been able to test this in the simulator. And allow access to contacts is enabled.
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.21 SR4.1
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
No response
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: