MediaPlugin: [iOS] iOS 14, ObjectDisposedException MediaPickerController

An ObjectDisposedException is thrown when taking photo with TakePhotoAsync. However it doesn’t crash and the photo can still be used.

Here is exception details: System.ObjectDisposedException Message=Cannot access a disposed object. Object name: 'MediaPickerController'.

As you proposed I tried to migrate to Xamarin.essentials.MediaPicker unfortunatly it is currently missing options (at least AllowCropping, DefaultCamera and RotateImage) and the multiple pictures pick is not proposed.

Bug Information

Version Number of Plugin: 5.0.1 Device Tested On: iPhone XR Version of VS: 16.7.7 Version of Xamarin: 16.7.000.463 Versions of other things you are using: Version of Xamarin;iOS: 14.2.0.12

Steps to reproduce the Behavior

Call TakePhotoAsync

Expected Behavior

No exception thrown

Actual Behavior

An ObjectDisposedException is thrown

Screenshots

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Had a similar issue (probably the same) with the following stacktrace:

    Type: System.ObjectDisposedException
    Message: "Cannot access a disposed object.
Object name: 'Foundation.InternalNSNotificationHandler'."
    Stacktrace:
      at ObjCRuntime.ThrowHelper.ThrowObjectDisposedException (System.Object o) [0x00000] in /Users/xyz/_work/1/s/xamarin-macios/src/ObjCRuntime/ThrowHelper.cs:34 
      at ObjCRuntime.NativeObjectExtensions.GetNonNullHandle (ObjCRuntime.INativeObject self, System.String argumentName) [0x0001b] in /Users/xyz/_work/1/s/xamarin-macios/src/ObjCRuntime/INativeObject.cs:29 
      at Foundation.NSNotificationCenter.RemoveObserver (Foundation.NSObject observer) [0x00000] in /Users/xyz/_work/1/s/xamarin-macios/src/build/ios/native/Foundation/NSNotificationCenter.g.cs:179 
      at Plugin.Media.MediaPickerDelegate.RemoveOrientationChangeObserverAndNotifications () [0x00012] in d:\a\1\s\src\Media.Plugin\iOS\MediaPickerDelegate.cs:197 
      at Plugin.Media.MediaPickerDelegate.Canceled (UIKit.UIImagePickerController picker) [0x00000] in d:\a\1\s\src\Media.Plugin\iOS\MediaPickerDelegate.cs:100 
      at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
      at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/xyz/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86 
      at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/xyz/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65 
      at MyApplication.iOS.Application.Main (System.String[] args) [0x00024] in C:\SVN\MyApplication\MyApplication.iOS\Main.cs:19 

Versions: Xam.Plugin.Media: 5.0.1 iOS: 14.4 Xamarin.Forms: 5.0.0.2012 Visual Studio: 16.9.1 IDB: 16.9.000.271 Device: iPhone 12 Pro (Simulator)

@volcano619 thanks. I can confirm that so far my end user seeing this issue is unable to do so with the changes introduced. I must admit even they couldn’t reproduce it regularly though

If anyone wants to give a stab at fixing this issue, let me know and I will give you all some pointers! @volcano619 @callumideagen @flipper09112 @pspeybro !

Essentially, (save your changes first), then use the debuggable version of this library:

  1. clone this repository and
  2. add the CSProj from here https://github.com/jamesmontemagno/MediaPlugin/tree/master/src/Media.Plugin into your own solution.
  3. Edit references for each of your projects and include this project as a reference
  4. Remove the MediaPlugin nuget package you have installed
  5. Try to build and you should have no issues building

Then during the runtime

  1. Place an exception catch-point and when you select your image, you should see the exception is caught on Line 56 of the MediaPickerController in the iOS project
  2. Try to fix the bug by playing around with the code.
  3. Once you get there, let me know what you have tried!

Hello, Any update on this issue? Cannot use xamarin essentials as we need to support image compression 😦 .