Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarin.Forms Android throws "Cannot access a closed Stream" exception #696

Closed
BurningAXE opened this issue Aug 17, 2017 · 5 comments
Closed

Comments

@BurningAXE
Copy link

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.

@daniel-luberda
Copy link
Member

daniel-luberda commented Aug 22, 2017

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.

@daniel-luberda
Copy link
Member

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

@daniel-luberda
Copy link
Member

More here: https://github.com/luberda-molinet/FFImageLoading/wiki/Data-URL-&-Embedded-Resources-support-(including-base64)

@BurningAXE
Copy link
Author

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

@daniel-luberda
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants