FFImageLoading
FFImageLoading copied to clipboard
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:
- [X] :iphone: iOS
- [ ] :robot: Android
- [ ] :checkered_flag: WPF
- [ ] :earth_americas: UWP
- [ ] :apple: MacOS
- [ ] :tv: tvOS
- [x] :monkey: Xamarin.Forms
My bad, the Samples project works for the same exact configuration so it must be something on my end.
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?
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.
The issue is not present when debugging on Android so Hot Restart feature obviously has something to do with it. All I was able to find is that the sourceStream.ReadAsync
from here always returns 0 for the bytes read and therefore outputStream.Length
always equals 0 which causes the error to be thrown. response.Content
from the same file does however return correct HTTP code and headers as far as I can tell.
I get this error. Image not load from URLs
same error here, debugging from a mac, no image is showed
same here
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)));
Same error here.
iOS, Newest Versions of Libraries.
I solved it, make sure to download the latest Xamarin.iOS by using visual studio!! I had to choose the Preview channel just make sure you have the latest XF and Xamarin.iOS
I followed @wocar 's instructions. Ran the latest XF and Xamarin.iOS w/ The Preview channel. This did not resolve the issue for me.
Can you share your visual studio about page that shows all the versions of all the SDKs that you have installed
Like I said above, you can clone the ffimageloading repo and compile from source and use the .dll-s in your project instead of Nuget packages. This solves the issue for now, until @daniel-luberda or someone else can fix this.
Like I said above, you can clone the ffimageloading repo and compile from source and use the .dll-s in your project instead of Nuget packages. This solves the issue for now, until @daniel-luberda or someone else can fix this.
I'm unable to build it on OSX due to a variety of type errors. That being said - Why does building it via DLLs work and Nuget does not when they should be in sync?
=== Visual Studio Community 2019 for Mac (Preview) ===
Version 8.7 Preview (8.7 build 522)
Installation UUID: 60a00c41-335e-4a68-941a-4c8c27a8b1d2
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
Package version: 612000073
=== Mono Framework MDK ===
Runtime:
Mono 6.12.0.73 (2020-02/d6f0c25d34d) (64-bit)
Package version: 612000073
=== Roslyn (Language Service) ===
3.6.0-3.20210.9+4eafdcb1bcbd8d3573f2ba6065e56d9b9ce4f8a3
=== NuGet ===
Version: 5.6.0.6591
=== .NET Core SDK ===
SDK: /usr/local/share/dotnet/sdk/3.1.300/Sdks
SDK Versions:
3.1.300
3.1.101
3.0.100
3.0.100-rc1-014190
3.0.100-preview9-014004
3.0.100-preview6-012264
2.1.700
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks
=== .NET Core Runtime ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.4
3.1.1
3.0.0
3.0.0-rc1-19456-20
3.0.0-preview9-19423-09
3.0.0-preview6-27804-01
2.1.18
2.1.15
2.1.13
2.1.11
=== Xamarin.Profiler ===
Version: 1.6.12.29
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Updater ===
Version: 11
=== Xamarin.Android ===
Version: 10.3.99.230 (Visual Studio Community)
Commit: xamarin-android/d16-7/1c21f5c
Android SDK: /Users/digi/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.6
SDK Build Tools Version: 28.0.3
Build Information:
Mono: 051408e
Java.Interop: xamarin/java.interop/d16-7@6608c59
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.31.1@49232bc
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@12f52ac
=== Microsoft Mobile OpenJDK ===
Java SDK: /Users/digi/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Android SDK Manager ===
Version: 16.6.0.56
Hash: c4cd6b3
Branch: remotes/origin/d16-7
Build date: 2020-04-30 04:52:44 UTC
=== Android Device Manager ===
Version: 16.6.0.115
Hash: 15b9321
Branch: remotes/origin/d16-7
Build date: 2020-04-30 04:53:06 UTC
=== Xamarin Designer ===
Version: 16.7.0.155
Hash: 03858dcd7
Branch: remotes/origin/d16-7
Build date: 2020-04-27 18:53:20 UTC
=== Apple Developer Tools ===
Xcode 11.5 (16139)
Build 11E608c
=== Xamarin.Mac ===
Version: 6.20.0.20 (Visual Studio Community)
Hash: bced85e1a
Branch: d16-7
Build date: 2020-05-04 18:27:38-0400
=== Xamarin.iOS ===
Version: 13.20.0.20 (Visual Studio Community)
Hash: bced85e1a
Branch: d16-7
Build date: 2020-05-04 18:27:38-0400
=== Build Information ===
Release ID: 807000522
Git revision: e60ad3eae1b5bfc65148c1253baf22bd48a0ce3f
Build date: 2020-05-18 10:11:32-04
Build branch: release-8.7
Xamarin extensions: e60ad3eae1b5bfc65148c1253baf22bd48a0ce3f
=== Operating System ===
Mac OS X 10.15.4
Darwin 19.4.0 Darwin Kernel Version 19.4.0
Wed Mar 4 22:28:40 PST 2020
root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
Same issue for me.
Perhaps this tidbit will be helpful: I am getting this sort of error (and not having my svg images load) as well, but only on a physical device (running iOS 13.4.1). Running on a simulator (which is on 13.5), I get no problems. This is with Visual Studio for Windows 2019 (16.6.3).
I then upgraded the software on my iPhone to iOS 13.5.1, and I am no longer getting the error. Perhaps this was an iOS bug?
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 ;-)
I have same issue. than I try @PieEatingNinjas solution it worked. Thank you.
Can someone confirm if you as well have a weird ";240x0" at the end of each image uri? I can see in the log that it tries to download the images, but with an incorrect uri
Can someone confirm if you as well have a weird ";240x0" at the end of each image uri? I can see in the log that it tries to download the images, but with an incorrect uri
I got this too, the url I displayed in the debug output is https://{host}.png;258x0;CircleTransformation,borderSize=0,borderHexColor=, but the image still load failed after I processed the url in the server side.
Same issue here.
Weirdly I'm also seeing the urls change;
https://storage.googleapis.com/assets.test.io/original.jpg
becomes:
https://storage.googleapis.com/assets.test.io/original.jpg;0x450
With the addition of the ;0x450 to the end.
The change of the URLs is not an actual change of the URL. It's just the cache key that the library uses. You can make your own if you wish.
Was this issue resolved?
No, still present as of yesterday.
@Inrego thanks for the info, then I don't have any clues on why images aren't loading.
I'm not sure, but it may be related to some of the limitations of Hot Restart: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/deploy-test/hot-restart#limitations
Same issue here as of today. VS 16.8.3 on Windows 10 with a physical iPhone X with iOS 14.2.
iOS version: 14.6 FFImageLoading version: 2.4.11.982
This seems to be related to the usage of CircleTransformation or FFImageLoading.Transformations in general.
After some testing I was able to re-create this with a loaded gif that has a transformation
<ffimageloading:CachedImage
Aspect="AspectFit"
Source="{Binding Image}"
Margin="0">
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation />
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
This caused the GIF not to load on iOS but loaded on android.
After removing the entire transformation section:
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation />
</ffimageloading:CachedImage.Transformations>
The image loaded on iOS
Hopefully this will help resolve this issue
my soultion was to copy this class into my project and https://github.com/luberda-molinet/FFImageLoading/blob/v2.4.11/source/FFImageLoading.Common/Cache/DownloadCache.cs initalize it whit ImageServiceInstance
Configuration config = new Configuration(); // your project config
#if DEBUG
// without it images don't load on iOS hot reload
var downloadCache = new MyDownloadCache(config);
config.DownloadCache = downloadCache;
#endif
ImageService.Instance.Initialize(config);