Xamarin.forms: [Bug] Android ImageRenderer throws ObjectDisposedException

Created on 16 Dec 2019  路  10Comments  路  Source: xamarin/Xamarin.Forms

Description

Android Application crashed with ObjectDisposedException. Stack trace points to ImageElementManager.cs code that was changed by the introduction of gif animated images.

Steps to Reproduce

  1. Use Images in GroupableItemsView (such as a Collectionview)
  2. Force the application to dispose some of these images
  3. ImageRenderer->OnElementChanged -> ImageElementManager.TryUpdateImage throw in line 139

Expected Behavior

Application does not crash by either catching the ObjectDisposedException or checking for disposal

proposed fix: #8906

Actual Behavior

Application crashes.

Basic Information

  • Version with issue: 4.4
  • Last known good version: 4.3
  • IDE: Visual Studio
  • Platform Target Frameworks: Android 5.1+
  • Android Support Library Version: 28.0.0.3
  • Nuget Packages:
  • Affected Devices:

Reproduction Link

-- will try to create a repro --

Stack Trace:
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'. at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Android.Widget.ImageView.get_Drawable () [0x0000a] in <82e50ec67af648c3b9f43b3d70e21b96>:0 at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.TryUpdateBitmap (Xamarin.Forms.Platform.Android.IImageRendererController rendererController, Android.Widget.ImageView Control, Xamarin.Forms.IImageElement newImage, Xamarin.Forms.IImageElement previous) [0x00111] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ImageElementManager.cs:139 at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.Android.VisualElementChangedEventArgs e) [0x00094] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ImageElementManager.cs:54 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.27(intptr,intptr) at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.27(intptr,intptr) --- End of inner exception stack trace ---

in-progress Android bug

All 10 comments

Same here

I see the same error:

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'.

I just encountered this. I have a page that immediately loads an image from an URL, but it takes a few seconds to load. If I load the page and then immediately back out to the previous page, the image will try to load after the page is already popped, and I get this error.

How did you fix the problem ?

Tested fix with nighly build. It solves the problem

I am experiencing same issue after upgrading to latest Xamarin Forms version 4.4.0.991265+398-sha.ee1eca51d-azdo.3306453 with the following error:

{System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 
  at Android.Widget.ImageView.get_Drawable () [0x0000a] in <11f101b564894ca7af6c482ddc51c698>:0 
  at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.TryUpdateBitmap (Xamarin.Forms.Platform.Android.IImageRendererController rendererController, Android.Widget.ImageView Control, Xamarin.Forms.IImageElement newImage, Xamarin.Forms.IImageElement previous) [0x00111] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ImageElementManager.cs:139 
  at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.Android.VisualElementChangedEventArgs e) [0x00094] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ImageElementManager.cs:54 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <11f101b564894ca7af6c482ddc51c698>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <11f101b564894ca7af6c482ddc51c698>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <11f101b564894ca7af6c482ddc51c698>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.18(intptr,intptr)}

Please when will the fix be available in latest update?

Thanks

@microwales :
Can you check on Xamarin Forms version 4.4.0.991477

I think, it has been fixed.

@microwales :
Can you check on Xamarin Forms version 4.4.0.991477

I think, it has been fixed.

Yes it is fixed in the latest package. Thanks @tendynewbies

Should be fixed on 4.4.0.991477

Was this page helpful?
0 / 5 - 0 ratings