FFImageLoading: ffimageloading DownloadException: Zero length stream with Xamarin Hot Restart on iPhone

πŸ› Bug Report

When using the latest Visual Studio 16.5 on Windows 10 with Xamarin’s Hot Restart enabled, ffimageloading throws FFImageLoading.Exceptions.DownloadException: Zero length stream error while trying to load an image.

Full exception log:

2020-03-21 00:40:45.532 Xamarin.PreBuilt.iOS[1184:451651] Image loading failed: https://s3-us-west-2.amazonaws.com/grial-images/v3.0/article_04.jpg
FFImageLoading.Exceptions.DownloadException: Zero length stream
  at FFImageLoading.Cache.DownloadCache.DownloadAsync (System.String url, System.Threading.CancellationToken token, System.Net.Http.HttpClient client, FFImageLoading.Work.TaskParameter parameters, FFImageLoading.DownloadInformation downloadInformation) [0x006bd] in C:\projects\ffimageloading\source\FFImageLoading.Common\Cache\DownloadCache.cs:174 
  at FFImageLoading.Cache.DownloadCache+<>c__DisplayClass15_0.<DownloadAndCacheIfNeededAsync>b__0 () [0x00050] in C:\projects\ffimageloading\source\FFImageLoading.Common\Cache\DownloadCache.cs:58 
  at FFImageLoading.Retry.DoAsync[T] (System.Func`1[TResult] action, System.TimeSpan retryInterval, System.Int32 retryCount, System.Action onRetry) [0x000b2] in C:\projects\ffimageloading\source\FFImageLoading.Common\Helpers\Retry.cs:24 
  at FFImageLoading.Cache.D
ng.Common\Work\ImageLoaderTask.cs:618 
ownloadCache.DownloadAndCacheIfNeededAsync (System.String url, FFImageLoading.Work.TaskParameter parameters, FFImageLoading.Config.Configuration configuration, System.Threading.CancellationToken token) [0x00401] in C:\projects\ffimageloading\source\FFImageLoading.Common\Cache\DownloadCache.cs:57 
  at FFImageLoading.DataResolvers.UrlDataResolver.Resolve (System.String identifier, FFImageLoading.Work.TaskParameter parameters, System.Threading.CancellationToken token) [0x00045] in C:\projects\ffimageloading\source\FFImageLoading.Common\DataResolvers\UrlDataResolver.cs:22 
  at FFImageLoading.DataResolvers.WrappedDataResolver.Resolve (System.String identifier, FFImageLoading.Work.TaskParameter parameters, System.Threading.CancellationToken token) [0x0004e] in C:\projects\ffimageloading\source\FFImageLoading.Common\DataResolvers\WrappedDataResolver.cs:21 
  at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,TImageContainer,TImageView].RunAsync () [0x00300] in C:\projects\ffimageloading\source\FFImageLoadi

Expected behavior

To load an image without the error.

Reproduction steps

Try using ffimageloading in any form or way on Windows 10 with Visual Studio 16.5 and Xamarin Hot Restart enabled while debugging on iPhone connected with USB.

Configuration

Version: 2.4.11.982

Platform:

  • πŸ“± iOS
  • πŸ€– Android
  • 🏁 WPF
  • 🌎 UWP
  • 🍎 MacOS
  • πŸ“Ί tvOS
  • πŸ’ Xamarin.Forms

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 32

Most upvoted comments

I’m seeing the exact same issue. I’m using version 2.4.11.982, Xamarin Forms version 4.8.0.1269 on iOS 13.6.1 (Hot Reload). On Android everything is working well.

Currently have a rather naive β€˜solution’:

public class SourceConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (Device.RuntimePlatform == Device.Android)
            return value;

        if(value != null)
            return ImageSource.FromStream(() => new MemoryStream(new WebClient().DownloadData(value.ToString())));

        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Source="{Binding DetailViewModel.HeaderImage, Converter={StaticResource sourceConverter}}"

Not proud of it, but it works. Hopefully someone can find the source of this issue, so we can leave out dirty hacks like this πŸ˜‰

same error here, debugging from a mac, no image is showed

I followed @wocar 's instructions. Ran the latest XF and Xamarin.iOS w/ The Preview channel. This did not resolve the issue for me.

My bad, the Samples project works for the same exact configuration so it must be something on my end.

I have the same issue. What’s the workaround?

This will sound strange, but I managed to get it to work by downloading the FFImageLoading solution and compiling it by myself and referencing the compiled .dll-s in my solution instead of the nuget packages (deleted those). But here is the strange part - it only works if I use the FFImageLoading .dll-s from debug folder. If I use the release ones, the same error pops up as the one in my original post. I did not have time to investigate this further, right now I just use the debug versions. I forgot to re-open this issue but I am doing so now.

@PieEatingNinjas that solution worked like a charm for me. Been struggling with this for ages.

Same error here.

iOS, Newest Versions of Libraries.

After a couple of days in frustration here is the couse of the bug I think: https://github.com/xamarin/Xamarin.Forms/issues/10800

Also here is my workarround:

foto.Source = ImageSource.FromStream(() => new MemoryStream(new WebClient().DownloadData(url)));