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

CollectionView with ItemTemplate containing Images with UriImageSource throws TaskCanceledException when scrolling #10632

Closed
F-Goncalves opened this issue Oct 12, 2022 · 7 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Milestone

Comments

@F-Goncalves
Copy link

Description

Hi,

I noticed in my app when running on iOS and macOS that the UriImageSource from the Images within my CollectionView ItemTemplate is throwing a TaskCanceledException:

System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Microsoft.Maui.Controls.StreamWrapper.GetStreamAsync(Uri uri, CancellationToken cancellationToken, HttpClient client)
   at Microsoft.Maui.Controls.UriImageSource.DownloadStreamAsync(Uri uri, CancellationToken cancellationToken)
Microsoft.Maui.Controls.UriImageSource: Warning: Error getting stream for https://static.wikia.nocookie.net/disney/images/4/42/Dr._Akita.png

This seems to happen when Images which are still being loaded are leaving the visual area of the CollectionView. I guess it happens when the UriImageSource is told to cancel the download operation of the image.

All these exceptions being thrown are apparently blocking the UI, which makes the app very unresponsive until all exceptions have been thrown.

Steps to Reproduce

  1. Clone the attached repository and run on iOS or macOS
  2. Quickly scroll through the CollectionView
  3. Observe blocking UI and TaskCanceledExceptions being printed into the Console
  4. Once Exceptions are not printed to Console anymore, UI becomes responsive again

Link to public reproduction project repository

https://github.com/F-Goncalves/.NET-MAUI-Workshop

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

iOS 15.5, MacOS 12.5.1

Did you find any workaround?

No response

Relevant log output

No response

@F-Goncalves F-Goncalves added the t/bug Something isn't working label Oct 12, 2022
@PureWeen PureWeen added platform/iOS 🍎 area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Oct 12, 2022
@PureWeen PureWeen added this to the Backlog milestone Oct 12, 2022
@ghost
Copy link

ghost commented Oct 12, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@espenrl
Copy link
Contributor

espenrl commented Oct 19, 2022

I have the same problem using a CarouselView. It is set up with 5 image URIs. On page load (and setup of the CarouselView) it fires http GET and cancels the request, only to start another one right after. This happens for all 5 items.

I don't think it is related to specific platforms, but rather an effect of the recycling child items logic (I use WinUI and .NET 7 RC2).

The list of exceptions throws is quite remarkable, and no wonder it makes the UI sluggish.

Exception thrown: 'System.IO.IOException' in System.Net.Sockets.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Net.Security.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Net.Sockets.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Net.Security.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Net.Http.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll

@espenrl
Copy link
Contributor

espenrl commented Oct 19, 2022

I also tried setting ItemsSource on CarouselView.Loaded event. It didn't help. My thought was to wait after page layout was completed before loading the items.

@espenrl
Copy link
Contributor

espenrl commented Oct 24, 2022

NOTE: This is for Windows. The original bug report is for iOS and macOS.

ItemsContentControl.Realize() ends up calling ImageHandler.MapSource() twice, effectively cancelling the first load in ImageSourceServiceResultManager.BeginLoad().

Callstack first call to ImageHandler.MapSource()
ok

Callstack second call to ImageHandler.MapSource() which cancel the first one
error

@espenrl
Copy link
Contributor

espenrl commented Oct 25, 2022

@PureWeen Hi Shane, I saw you were one of the last people to code on ItemContentControl. I would love to get some tips on how this could be fixed, and then I could do a PR on it. See the post above.

@homeyf
Copy link

homeyf commented Aug 31, 2023

Verified this issue with VSM 17.6.4 (build 454). Not repro on iOS and maccatalyst platform with sample project.
https://github.com/F-Goncalves/.NET-MAUI-Workshop
image

@homeyf homeyf added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Aug 31, 2023
@ghost
Copy link

ghost commented Aug 31, 2023

Hi @F-Goncalves. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost closed this as completed Sep 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 7, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants