Ffimageloading: Xamarin.Forms Android throws "Cannot access a closed Stream" exception

Created on 17 Aug 2017  路  5Comments  路  Source: luberda-molinet/FFImageLoading

If you have an image as an embedded resource in the common PCL project and do:
cachedImage.Source = ImageSource.FromResource("ProjectName.Resources.image.png");
in more than one place in the same screen you get the above mentioned exception. The same code works fine in iOS.
Moving the image to the platform projects and getting the image source with ImageSource.FromFile() works fine.

Most helpful comment

Just replace ImageSource.FromResource with new EmbeddedResourceImageSource("ProjectName.Resources.image.png")

All 5 comments

Just add a custom cache key which will always return ProjectName.Resources.image.png for the same file and you're done (only one image loading for the same file will occur). By default StreamImageSource (which ImageSource.FromResource is), uses Stream hash as a key.

OR you can use EmbeddedResourceImageSource which takes care of it for you and generally, has a better performance. Also resource:// string urls are supported.

Great! If it's not too much trouble can you give some usage examples for people not-so-familiar with .NET ashamed

Just replace ImageSource.FromResource with new EmbeddedResourceImageSource("ProjectName.Resources.image.png")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

K232 picture K232  路  3Comments

jdbrock picture jdbrock  路  4Comments

matheusvelloso picture matheusvelloso  路  4Comments

Pinox picture Pinox  路  5Comments

abenedykt picture abenedykt  路  3Comments