question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
daniel-luberdacommented, Aug 22, 2017

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

2reactions
daniel-luberdacommented, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found