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
The image is still empty, the persisted error is loaded again.
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
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.
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).
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. ;)
Should be fixed in 2.2.0-pre1.
I have checked this issue with Xamarin.Forms 220.127.116.11-pre1 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.