Bug 39359 - Image View does cache failed HTTP responses
Summary: Image View does cache failed HTTP responses
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.1.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2016-03-04 12:33 UTC by Stefan Reinhard
Modified: 2017-02-02 12:32 UTC (History)
6 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Stefan Reinhard 2016-03-04 12:33:22 UTC

The Xamarin.Forms image cache does persist HTTP errors in the image cache instead of ignoring them.

Steps to reproduce

1) Load an Image with UriImageSource and caching enabled that returns a 404 or any other HTTP error
2) Make sure the same Uri now does provide a valid image
3) Load the Image from the same location again

Actual Results

The image is still empty, the persisted error is loaded again.

Expected Results

The error should not have been cached and the image now loads successfully.

Affected Builds and Hardware

All Xamarin.Forms versions from 1.3 up to 2.1 show the same behaviour

The Error happens only on iOS, Android is not affected
Comment 1 Philipp 2016-03-04 12:55:36 UTC
The problem seems to be that UriImageSource.GetStreamAsyncUnchecked uses Device.GetStreamAsync which does not check for successful HTTP status codes. Therefore any result will be cached a few lines below.
Comment 3 Roger Peters 2016-03-24 16:08:34 UTC
Seems like the only real workaround would be to implement dependency services that can try and read from the ImageLoaderCache and delete the entry if it's filesize is 0.. ? Would really love to see this fixed, without it I can't actually use the image cacheing abilities (which otherwise work great).
Comment 4 Philipp 2016-03-24 16:13:00 UTC
We implemented a workaround like this and delete empty cache files. This works fine as long as your server does not send any content in the body of the error response. If you get a body, it will be stored in the cache file and it's going to be hard to find those. ;)
Comment 5 Samantha Houts [MSFT] 2016-03-30 20:37:07 UTC
Should be fixed in 2.2.0-pre1.
Comment 7 Parmendra Kumar 2017-02-02 12:32:50 UTC
I have checked this issue with Xamarin.Forms and observed that this issue has been fixed. To verify this issue I have used the sample project attached in comment #2. Image render successfully when upload on provided empty url.

If you still getting same issue please feel free to reopen this issue or filed the separate issue for the same.