Xamarin.Forms Android throws "Cannot access a closed Stream" exception
See original GitHub issueIf 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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
c# - Cannot access a closed stream Exception
1 Answer 1 ... You're disposing of the MemoryStream because you're using a using block. By the time you try to use the...
Read more >[BUG] **System.ObjectDisposedException:** 'Can not ...
I get the following exception on Android in a Xamarin.Android native app: System.ObjectDisposedException: 'Can not access a closed Stream.'
Read more >Cannot access a closed stream - Microsoft Q&A
I am noticing lots of httpclient errors in my app. This one says: System.ObjectDisposedException: Cannot access a closed Stream. Copy.
Read more >'Can not access a closed Stream.' exception when trying to ...
ObjectDisposedException : 'Can not access a closed Stream.' exception when trying to download an image from the Internet Xamarin Forms ...
Read more >[Solved]-Cannot access a closed stream Exception-C#
You're disposing of the MemoryStream because you're using a using block. By the time you try to use the return value later in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just replace
ImageSource.FromResource
withnew EmbeddedResourceImageSource("ProjectName.Resources.image.png")
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 defaultStreamImageSource
(whichImageSource.FromResource
is), uses Stream hash as a key.