xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] PushModalAsync on first run causes ObjectDisposedException for PlatformRenderer in iOS #7406

Open wadebaird opened 5 years ago

wadebaird commented 5 years ago

Description

We are developing a Xamarin project with a Login Screen using Xamarin.Auth. Throughout using the application the user will need to re-authenticate if the session has elapsed. As I understand it, the proper way is load the Login screen as a modal page over the front of the current screen, and force the user to re-login.

On iOS when attempting to do this I get this exception: System.ObjectDisposedException: 'Cannot access a disposed object. Object name: 'PlatformRenderer'.'

with this callstack:

    0x1D in Foundation.NSObject.get_SuperHandle at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/Foundation/NSObject2.cs:449,6 C#
    0x2B in UIKit.UIViewController.get_View at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/UIKit/UIViewController.g.cs:3037,6    C#
    0x57 in Xamarin.Forms.Platform.iOS.Platform.EndEditing at D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:464,4 C#
    0x1 in Xamarin.Forms.Platform.iOS.Platform.Xamarin.Forms.INavigation.PushModalAsync at D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:145,4    C#
    0x25 in Xamarin.Forms.Internals.NavigationProxy.OnPushModal at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:212,4 C#
    0x3 in Xamarin.Forms.Application.NavigationImpl.<>n__1  C#
    0x72 in Xamarin.Forms.Application.NavigationImpl.OnPushModal at D:\a\1\s\Xamarin.Forms.Core\Application.cs:395,6    C#
    0x33 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Xamarin.Forms.Application.NavigationImpl.<OnPushModal>d__3> at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316,17  C#
    0x37 in Xamarin.Forms.Application.NavigationImpl.OnPushModal    C#
    0x16 in Xamarin.Forms.Internals.NavigationProxy.PushModalAsync at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:129,4  C#
    0x25 in Xamarin.Forms.Internals.NavigationProxy.OnPushModal at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:212,4 C#
    0x16 in Xamarin.Forms.Internals.NavigationProxy.PushModalAsync at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:129,4  C#
    0x25 in Xamarin.Forms.Internals.NavigationProxy.OnPushModal at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:212,4 C#
    0x16 in Xamarin.Forms.Internals.NavigationProxy.PushModalAsync at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:129,4  C#
    0x25 in Xamarin.Forms.Internals.NavigationProxy.OnPushModal at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:212,4 C#
    0x16 in Xamarin.Forms.Internals.NavigationProxy.PushModalAsync at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:129,4  C#
    0x3 in Xamarin.Forms.Internals.NavigationProxy.PushModalAsync at D:\a\1\s\Xamarin.Forms.Core\NavigationProxy.cs:122,4   C#
>   0xB0 in ONPoint.Views.LoginPage.CreateAndOpen at C:\source\onpoint\ONPoint\Views\LoginPage.xaml.cs:76,13    C#
    0x6 in System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1092,17  C#
    0x73 in System.Threading.ExecutionContext.RunInternal at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968,17  C#
    0x4 in System.Threading.ExecutionContext.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910,13   C#
    0x32 in System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1073,25    C#
    0x6 in System.Threading.Tasks.AwaitTaskContinuation.InvokeAction at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:601,58 C#
    0x11 in System.Threading.Tasks.AwaitTaskContinuation.RunCallback at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:628,17 C#
    0x21 in System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:406,17   C#
    0xA7 in System.Threading.Tasks.Task.FinishContinuations at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:3190,21 C#
    0x3D in System.Threading.Tasks.Task.FinishStageThree at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2222,13    C#
    0x50 in System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:422,17    C#
    0x3F in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:608,17   C#
    0x1A in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:636,17   C#
    0xB in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:378,13   C#
    0x170 in Acr.UserDialogs.AbstractUserDialogs.AlertAsync at C:\dev\userdialogs\src\Acr.UserDialogs\AbstractUserDialogs.cs:125,9  C#
    0x6 in System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1092,17  C#
    0x73 in System.Threading.ExecutionContext.RunInternal at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968,17  C#
    0x4 in System.Threading.ExecutionContext.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910,13   C#
    0x32 in System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1073,25    C#
    0x6 in System.Threading.Tasks.AwaitTaskContinuation.InvokeAction at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:601,58 C#
    0x11 in System.Threading.Tasks.AwaitTaskContinuation.RunCallback at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:628,17 C#
    0x21 in System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:406,17   C#
    0xA7 in System.Threading.Tasks.Task.FinishContinuations at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:3190,21 C#
    0x3D in System.Threading.Tasks.Task.FinishStageThree at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2222,13    C#
    0x50 in System.Threading.Tasks.Task<object>.TrySetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:422,17   C#
    0x7 in System.Threading.Tasks.TaskCompletionSource<object>.TrySetResult at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/TaskCompletionSource.cs:274,13  C#
    0x7 in Acr.UserDialogs.AbstractUserDialogs. at C:\dev\userdialogs\src\Acr.UserDialogs\AbstractUserDialogs.cs:118,37 C#
    0x10 in Acr.UserDialogs.UserDialogsImpl. at C:\dev\userdialogs\src\Acr.UserDialogs\Platforms\ios\UserDialogsImpl.cs:32,98   C#
    0x1D in ObjCRuntime.Trampolines.SDActionArity1V184.Invoke at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/ObjCRuntime/Trampolines.g.cs:24840,6    C#
    0x66 in UIKit.UIApplication.UIApplicationMain   C#
    0xB in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/UIKit/UIApplication.cs:86,4   C#
    0x11 in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/UIKit/UIApplication.cs:65,5  C#
    0x8 in ONPoint.iOS.Application.Main at C:\source\onpoint\ONPoint.iOS\Main.cs:17,13  C#

This is most likely related to #2208, which has been closed due to lack of repro. My reproduction is consistent, and occurs everytime.

Steps to Reproduce

I have a private repro solution that I can provide (has some company information in it, so would like to keep it private).

  1. Utilize Xamarin.Auth framework for authn/z
  2. Load the login page via this code: await currentPage.Navigation.PushModalAsync(new LoginPage(onLoginFunction));

Expected Behavior

Form is loaded in Modal mode.

Actual Behavior

Exception occurs

Basic Information

samhouts commented 5 years ago

@wadebaird Please send a link to your repro to sahou at microsoft. Thanks!

wadebaird commented 5 years ago

Thanks! Email w/ repro sent

samhouts commented 5 years ago

Haven't received email yet. :)

samhouts commented 5 years ago

@wadebaird I've tested your reproduction, and I do not see a crash. Your repro steps indicate that I should simply click login to launch the modal page, and it should crash. Is that right? Do you see this exception on simulators or only on device? Which sim/device are you testing with? Thanks!

wadebaird commented 5 years ago

Thanks @samhouts. The repro steps are more involved than that, please look at the original email. I sent you a reply with the repro steps at the top of the email and copied them here (minus the UN / PW):

Load the app, click on the “Login” button on the login page, then use these credentials:

xxxxxxxx xxxxxxxx

Then on the next screen click on the “Click here to repro”. On the popup about “re-logging in” click “OK” The first exception you encounter will be a SessionExpiredException which is expected, it triggers the loading of the LoginPage to re-login. Then the next exception should be the PlatformRenderer exception.

samhouts commented 5 years ago

Ah, yep, sorry about that! I missed that part of the email. Will try again.

klogeaage commented 5 years ago

I have the same problem, but triggered from using Microsoft AppCenter Auth. Essentially, it breaks modal dialogs in Xamarin.Forms, no matter what you use them for. I think I could also produce a sample if necessary. It certainly is pretty serious.

PureWeen commented 5 years ago

@klogeaage do you have a repro you can send?

@wadebaird sent you an email about the credentials

jfversluis commented 5 years ago

@klogeaage a friendly reminder that a reproduction would be greatly appreciated if you have one!

klogeaage commented 5 years ago

Hi @PureWeen & @jfversluis, sorry but because of this issue, I abandoned using modal views in my current app, and now I can't seem to reproduce the issue anymore. A lot of updates have taken place in both my, Microsofts and Apples code, and now the crash no longer happens when I invoke a modal dialog. From my perspective, you may close the issue.

jfversluis commented 5 years ago

Thanks for the update @klogeaage! @wadebaird, are you seeing this as well? 🙂

wadebaird commented 4 years ago

Thanks @jfversluis. I haven't tried this in iOS 13 yet, but it failed in iOS 12 the last time I tried it. We can't force our users to iOS13, so it would be great to get this fixed.

wadebaird commented 4 years ago

@kingces95 Can you explain why this has the "needs-repro" tag? I have provided a repro and I believe they can reproduce it. Thanks!

jfversluis commented 4 years ago

@wadebaird I don't see where I said that iOS 13 has the solution? :)

@klogeaage mentioned that he updated Microsoft stuff, so I think XamForms (maybe also Xamarin.Auth?) and Apple things, by which I think he means the latest XCode and the latest Xamarin.Forms version which still runs on iOS 12 as well as 13. All I meant to ask you was if you are able to update to the latest and greatest to see if that fixes your problem.

wadebaird commented 4 years ago

Sorry @jfversluis, for some reason I thought I saw an update / email on this about it not reproducing in iOS13, my confusion.

I retested with the latest XamForms v4.3.0.947036 and get the same results on iOS12.4. On iOS 13.1 there is very strange behavior. The modal form loads without exception, but clicking on the login button on the form does nothing, unless I minimize the app, and then come back to it, and then it will show the ADFS login screen from Xamarin.Auth, but then logging into that it crashes after.

wadebaird commented 4 years ago

Ok @jfversluis , now I found the reference, it was in an email from @PureWeen stating "It’s funny (annoying) because it doesn’t crash on iOS 13 devices only iOS 12 devices". Thanks!

ricardoboss commented 4 years ago

Any updates on this?