-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
[BUG] **System.ObjectDisposedException:** 'Can not access a closed Stream.' #479
Comments
any chance of a mini repro please? also does it do it on the emulator? |
Sorry, updated the wrong issue. Update:Started to dig into this and finally came to a solution that works fine. I hope you find it useful. And the solution: This works for jpg and png images. I am happy to send a pull request with the fix.
|
I am putting together a sample soon. |
The same issue exists on API 23, Android 6.0 emulator too. |
the previous fixes related to a new version of xamarin forms. so as long as the emulator doing it as well can stick the test harness app on there to check it :) |
We are getting the same exception thrown in a .net standard library referenced from a Xamarin.Android project. Exception
nuget/project versions Xamarin.Android project .net Standard project Xamarin.Android project code
This is the called in the first activity to load when the app starts. .net Standard project code
The exception is thrown as a result of the call to LoadImageFromUrl. It can't be caught with try/catch. The stack trace above is taken from Microsoft App Center crash logs. Environment Worth noting the same error is not present in a Xamarin.iOS app referencing the same .net standard library (also updated to the latest Splat and Akavache versions). As a temporary fix we have dropped back to akavache v6.5.9 where LoadImageFromUrl was available in this package (not Akavache.Drawing). |
This is still happening with Akavache 6.10.20 and Akavache.Drawing 6.10.20. Calling BlobCache.LocalMachine.LoadImageFromUrl in a Xamarin.Android project will result in a "System.ObjectDisposedException: Cannot access a closed Stream" Exception:
Here is an example project to replicate the issue. It's a basic "out of the box" Xamarin.Android project following the basic setup steps for Akavache. The example image url points to the ReactiveUI logo on the ReactiveUI homepage. Once the app has loaded, tap the icon at the bottom right of the main screen to call LoadImageFromUrl(). An exception will be thrown on line 62 in MainActivity.cs. I am debugging directly on a Samsung S9 device running Android 10. If anyone has a chance to look into this that would be most appreciated. In the mean time, we have dropped back to akavache v6.5.9 (where LoadImageFromUrl was available in this package and not Akavache.Drawing). |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
I get the following exception on Android in a Xamarin.Android native app:
System.ObjectDisposedException: 'Can not access a closed Stream.'
The app crashes after starting in debug mode. The app doesn't crash when starting from the icon on the device normally, but doesn't load any images.
StackTrace:
03-19 13:51:50.917 I/MonoDroid( 4650): UNHANDLED EXCEPTION:
03-19 13:51:50.921 I/MonoDroid( 4650): System.ObjectDisposedException: Can not access a closed Stream.
03-19 13:51:50.922 I/MonoDroid( 4650): at System.IO.MemoryStream.EnsureNotClosed () [0x00008] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/Common/src/CoreLib/System/IO/MemoryStream.cs:121
03-19 13:51:50.922 I/MonoDroid( 4650): at System.IO.MemoryStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0004e] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/Common/src/CoreLib/System/IO/MemoryStream.cs:369
03-19 13:51:50.922 I/MonoDroid( 4650): at Android.Runtime.InputStreamAdapter.Read (System.Byte[] bytes, System.Int32 offset, System.Int32 length) [0x00006] in <4a189ea3b82b48a089ac9002b2abc206>:0
03-19 13:51:50.922 I/MonoDroid( 4650): at Java.IO.InputStream.n_Read_arrayBII (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_b, System.Int32 off, System.Int32 len) [0x00020] in <4a189ea3b82b48a089ac9002b2abc206>:0
03-19 13:51:50.922 I/MonoDroid( 4650): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.49(intptr,intptr,intptr,int,int)
03-19 13:51:50.924 W/Looper ( 4650): Slow Looper main: Long Msg: seq=148 plan=13:51:26.895 late=97ms wall=23926ms running=896ms runnable=161ms h=android.os.Handler c=mono.java.lang.RunnableImplementor
03-19 13:51:50.930 I/Choreographer( 4650): Skipped 1438 frames! The application may be doing too much work on its main thread.
03-19 13:51:50.938 W/acsalbert.elll( 4650): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
03-19 13:51:50.942 D/Mono ( 4650): DllImport searching in: '__Internal' ('(null)').
03-19 13:51:50.942 D/Mono ( 4650): Searching for 'java_interop_jnienv_throw'.
03-19 13:51:50.942 D/Mono ( 4650): Probing 'java_interop_jnienv_throw'.
03-19 13:51:50.942 D/Mono ( 4650): Found as 'java_interop_jnienv_throw'.
03-19 13:51:50.977 W/acsalbert.elll( 4650): Attempt to remove index outside index area (0 vs 1-1)
03-19 13:51:50.977 W/acsalbert.elll( 4650): JNI WARNING: DeleteLocalRef(0x5) failed to find entry
03-19 13:51:50.987 F/acsalbert.elll( 4650): java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: JNI CallStaticObjectMethodA called with pending exception android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Can not access a closed Stream.
03-19 13:51:50.987 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at System.IO.MemoryStream.EnsureNotClosed () [0x00008] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/Common/src/CoreLib/System/IO/MemoryStream.cs:121
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at System.IO.MemoryStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0004e] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/Common/src/CoreLib/System/IO/MemoryStream.cs:369
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at Android.Runtime.InputStreamAdapter.Read (System.Byte[] bytes, System.Int32 offset, System.Int32 length) [0x00006] in <4a189ea3b82b48a089ac9002b2abc206>:0
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at Java.IO.InputStream.n_Read_arrayBII (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_b, System.Int32 off, System.Int32 len) [0x00020] in <4a189ea3b82b48a089ac9002b2abc206>:0
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.49(intptr,intptr,intptr,int,int)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at int mono.android.runtime.InputStreamAdapter.n_read(byte[], int, int) (InputStreamAdapter.java:-2)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at int mono.android.runtime.InputStreamAdapter.read(byte[], int, int) (InputStreamAdapter.java:56)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at android.graphics.Bitmap android.graphics.BitmapFactory.nativeDecodeStream(java.io.InputStream, byte[], android.graphics.Rect, android.graphics.BitmapFactory$Options, long, long) (BitmapFactory.java:-2)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at android.graphics.Bitmap android.graphics.BitmapFactory.decodeStreamInternal(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory$Options) (BitmapFactory.java:790)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at android.graphics.Bitmap android.graphics.BitmapFactory.decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory$Options) (BitmapFactory.java:765)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] at android.graphics.Bitmap android.graphics.BitmapFactory.decodeStream(java.io.InputStream) (BitmapFactory.java:806)
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570]
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] in call to CallStaticObjectMethodA
03-19 13:51:50.988 F/acsalbert.elll( 4650): java_vm_ext.cc:570] from int mono.android.runtime.InputStreamAdapter.n_read(byte[], int, int)
Steps To Reproduce
Update Splat and Splat.Drawing to version 9.3.11, and start the application.
Expected behavior
The app doesn't crash.
Versions
Splat version 9.3.11
Splat.Drawing version 9.3.11
Environment
The text was updated successfully, but these errors were encountered: