Mediaplugin: iOS - System.InvalidOperationException: The underlying NSMutableData changed while we were consuming data

Created on 28 Feb 2018  路  9Comments  路  Source: jamesmontemagno/MediaPlugin

Using latest pre-release. Trying to convert the File Stream to a Byte Array.

Does NOT happen: GetStream.
Does happen: GetStreamWithImageRotatedForExternalStorage

Is there something different/extra needed call GetStreamWithImageRotatedForExternalStorage ?

I would just use GetStream However in iOS the image isn't rotated correctly.

.NET Standard 2.0.1
iOS 11.3
Forms 2.5.0.280555
Media 3.1.3.222-beta

Media code:

                var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    AllowCropping = true,
                    RotateImage = true,
                    Directory = "imgs",
                    Name = "img.jpg",
                    SaveToAlbum = false,
                    DefaultCamera = CameraDevice.Rear,
                });

                using (var memoryStream = new MemoryStream())
                {
                    file.GetStreamWithImageRotatedForExternalStorage().CopyTo(memoryStream);
                    return memoryStream.ToArray();
                }

Exception:

System.InvalidOperationException: The underlying NSMutableData changed while we were consuming data

NSData+UnmanagedMemoryStreamWithMutableRef.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count)
Stream.InternalCopyTo (System.IO.Stream destination, System.Int32 bufferSize)
Stream.CopyTo (System.IO.Stream destination)
Extensions.ToByteArray (System.IO.Stream stream)
CameraHelper+<GetPhoto>d__0.MoveNext ()
ExceptionDispatchInfo.Throw ()
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
TaskAwaiter`1[TResult].GetResult ()
CellarListView+<HandleUpdatePhoto>d__5.MoveNext ()
ExceptionDispatchInfo.Throw ()
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
TaskAwaiter.GetResult ()
CellarListView+<OnItemSelected>d__4.MoveNext ()
ExceptionDispatchInfo.Throw ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 ()
NSAsyncActionDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

Most helpful comment

@Unitarian

I have Plugin.Permissions 2.2.1 and Plugin.Media 3.1.3 working together with GetStreamWithImageRotatedForExternalStorage

All 9 comments

Was able to get it working for now with 3.1.3 Stable.
3.1.3.222-beta fails.

                if (file != null)
                {
                    using (var stream = file.GetStreamWithImageRotatedForExternalStorage())
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            stream.CopyTo(memoryStream);
                            return memoryStream.ToArray();
                        }
                    }
                }

Downgrade it to version 3.1.3. Worked for me.

@aherrick @SkillerSKL
I downgraded to version 3.1.3 and getting following error now:

/Users/.../MTOUCH: Error MT2002: Failed to resolve "Plugin.Permissions.Abstractions.Permission" reference from "Plugin.Permissions.Abstractions, Version=2.2.1.0, Culture=neutral, PublicKeyToken=null" (MT2002) (ProjectName.iOS)

Which version of Plugin.Permissions is competible with version 3.1.3?

Regards,

@Unitarian

I have Plugin.Permissions 2.2.1 and Plugin.Media 3.1.3 working together with GetStreamWithImageRotatedForExternalStorage

@matgallacher me too. Staying put for now. Upgrading Permissions/Media has had build issues as well.

Can someone debug through the issue and send a PR?

Having the same issue after updating

Fixed in 4.0.1.X

I'm still having this issue on 4.0.1.5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irinakush picture irinakush  路  6Comments

Brosten picture Brosten  路  3Comments

Furqanali30 picture Furqanali30  路  7Comments

mdcso picture mdcso  路  4Comments

Greg-Freeman picture Greg-Freeman  路  7Comments