Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Cannot access a disposed object. Object name: 'PageContainer'. #13537

Open
TheCaveOfWonders opened this issue Jan 26, 2021 · 8 comments
Open

Comments

@TheCaveOfWonders
Copy link

TheCaveOfWonders commented Jan 26, 2021

Description

Removing a gesture recognizer that's inside a page's effect throws an exception: Cannot access a disposed object. Object name: 'PageContainer'.

Steps to Reproduce

Not always reproducible, but essentially we need to have a PlatformEffect with a gesture recognizer on a Xamarin.Forms.ContentPage. When the effect in question calls its OnDetached method, we will remove the gesture recognizer from the view

view.RemoveGestureRecognizer(touchRecognizer); 
where view is UIView and touchRecognizer is UIGestureRecognizer

Expected Behavior

no exception to be thrown

Actual Behavior

sometimes a Cannot access a disposed object. Object name: 'PageContainer' exception is thrown.

Basic Information

{
"length": 0,
"offset": 0,
"id": "33289256-779c-4472-8888-0ff5026e8e2d",
"exception": {
"type": "System.ObjectDisposedException",
"message": "Cannot access a disposed object.\nObject name: 'PageContainer'.",
"stackTrace": " at Foundation.NSObject.get_SuperHandle () <0x102098f50 + 0x000b8> in <cb9790ed00554382a298bf599d262d19#4922dbca770650d12adbda77259e98d2>:0 \n at UIKit.UIView.RemoveGestureRecognizer (UIKit.UIGestureRecognizer gestureRecognizer) <0x102064750 + 0x0005f> in <cb9790ed00554382a298bf599d262d19#4922dbca770650d12adbda77259e98d2>:0 \n at MyApp.iOS.Effects.TouchEffect.OnDetached () <0x10101d9e0 + 0x00047> in <7827dabf66d24c6d9cdc98f004d2651a#4922dbca770650d12adbda77259e98d2>:0 ",
"wrapperSdkName": "appcenter.xamarin"
},
"appId": "740135ec-5175-4c18-a6cd-5cb00b26883d",
"installId": "A063C386-E80A-40D8-BEC9-65E8B5CCD152",
"isTestMessage": false,
"timestamp": "2021-01-26T00:20:31.202Z",
"sid": "09155508-66a7-4eff-9cef-efdf6abc5711",
"userId": "4",
"device": {
"sdkName": "appcenter.ios",
"sdkVersion": "3.3.5+3621e27fb",
"wrapperSdkVersion": "3.4.3",
"wrapperSdkName": "appcenter.xamarin",
"model": "iPad5,3",
"oemName": "Apple",
"osName": "iOS",
"osVersion": "14.3",
"osBuild": "18C66",
"locale": "en_CA",
"timeZoneOffset": -240,
"screenSize": "2048x1536",
"appVersion": "5.0.4",
"appBuild": "14.0.4.10101",
"appNamespace": "com.MyApp",
"wrapperRuntimeVersion": "12.6.0"
}
}

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Professional 2019
Version 16.8.4
VisualStudio.16.Release/16.8.4+30907.101
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

ASP.NET and Web Tools 2019   16.8.557.25636
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.557.25636
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.8.557.25636
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.8.557.25636
Azure Functions and Web Jobs Tools

C# Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.8.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

OzCodePackage Extension   1.0
OzCodePackage Visual Studio Extension Detailed Info

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62012.31170
Microsoft SQL Server Data Tools

SQLite & SQL Server Compact Toolbox   4.7
SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

TypeScript Tools   16.0.21016.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Unity   4.8.2.0
Visual Studio Tools for Unity

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.261 (d16-8@bb99248)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.26 (d16-8/a36ce73)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc


Xamarin.iOS and Xamarin.Mac SDK   14.8.0.3 (c51fabee8)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
@TheCaveOfWonders TheCaveOfWonders added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 26, 2021
@rmarinho rmarinho added the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label Jan 26, 2021
@rmarinho
Copy link
Member

Hi @stanios thanks for your feedback, it will be really hard to try to understand this without a proper reproduction, can you please upload a small sample with the code you use?.

Thanks

@TheCaveOfWonders
Copy link
Author

TheCaveOfWonders commented Jan 26, 2021

I'll provide stack traces from a debug session, if you still need more info let me know and i'll see what I can do.

So it happens when we navigate away/to a page using shell navigation. It would seem like by the time the effect's OnDetached() is called, the page where the effect is on was already disposed of.

I am seeing something weird thought, when we navigate to a page (using shell) the effect's OnDetached() is called first for that page and then the OnAttached() is called.

This is the call stack of the page navigation that causes the crash down the line (see next call stack).

	at C:\MyApp\Controls\FieldPage.cs(41)
0x1 in MyApp.Pages.FlowLayoutPage.<>n__1
0x15 in MyApp.Pages.FlowLayoutPage.OnAppearing at C:\MyApp\Pages\FlowLayoutPage.cs:72,13
	at C:\MyApp\Pages\FlowLayoutPage.cs(72)
0x33 in System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<MyApp.Pages.FlowLayoutPage.<OnAppearing>d__9> at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84,17
0x27 in MyApp.Pages.FlowLayoutPage.OnAppearing
0x46 in Xamarin.Forms.Page.SendAppearing at D:\a\1\s\Xamarin.Forms.Core\Page.cs:434,4
0x41 in Xamarin.Forms.ShellContent.SendPageAppearing at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:125,5
0x2F in Xamarin.Forms.ShellContent.SendAppearing at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:106,4
0x27 in Xamarin.Forms.ShellSection.PresentedPageAppearing at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:820,6
0x7 in Xamarin.Forms.ShellSection.SendAppearing at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:930,4
0x33 in Xamarin.Forms.ShellItem.OnCurrentItemChanged at D:\a\1\s\Xamarin.Forms.Core\Shell\ShellItem.cs:299,6
0x12E in Xamarin.Forms.BindableObject.SetValueActual at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:463,5
0x17C in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397,5
0x5 in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:343,7
0x4 in Xamarin.Forms.Element.SetValueFromRenderer at D:\a\1\s\Xamarin.Forms.Core\Element.cs:248,4
0x334 in Xamarin.Forms.Shell.GoToAsync at D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:537,7
0x33 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Xamarin.Forms.Shell.<GoToAsync>d__102> at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316,17
0x3D in Xamarin.Forms.Shell.GoToAsync
0xC in Xamarin.Forms.Shell.GoToAsync at D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:478,4
0x155 in Xamarin.Forms.Shell.Xamarin-Forms-IShellController-OnFlyoutItemSelectedAsync at D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:384,5
0x33 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Xamarin.Forms.Shell.<Xamarin-Forms-IShellController-OnFlyoutItemSelectedAsync>d__87> at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316,17
0x2D in Xamarin.Forms.Shell.Xamarin.Forms.IShellController.OnFlyoutItemSelectedAsync
0x18 in Xamarin.Forms.Shell.Xamarin-Forms-IShellController-OnFlyoutItemSelected at D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:337,4
0x33 in System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<Xamarin.Forms.Shell.<Xamarin-Forms-IShellController-OnFlyoutItemSelected>d__86> at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84,17
0x2D in Xamarin.Forms.Shell.Xamarin.Forms.IShellController.OnFlyoutItemSelected
0xC in Xamarin.Forms.Platform.iOS.ShellFlyoutContentRenderer.OnElementSelected at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellFlyoutContentRenderer.cs:173,4
0x28 in Xamarin.Forms.Platform.iOS.ShellTableViewSource.RowSelected at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellTableViewSource.cs:143,4
0x66 in UIKit.UIApplication.UIApplicationMain
0xB in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86,4
0x11 in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65,5
0x8 in MyApp.iOS.Application.Main at C:\MyApp.iOS\Main.cs:12,13
	at C:\MyApp.iOS\Main.cs(12)

This is the call stack right before the crash

0x1C in MyApp.iOS.Effects.TouchEffect.OnDetached at C:\MyApp.iOS\Effects\TouchEffect.cs:51,21
	at C:\MyApp.iOS\Effects\TouchEffect.cs(51)
0xA in Xamarin.Forms.Effect.SendDetached at D:\a\1\s\Xamarin.Forms.Core\Effect.cs:62,4
0x1 in Xamarin.Forms.PlatformEffect<UIKit.UIView,UIKit.UIView>.SendDetached at D:\a\1\s\Xamarin.Forms.Core\PlatformEffect.cs:23,4
0xB in Xamarin.Forms.RoutingEffect.SendDetached at D:\a\1\s\Xamarin.Forms.Core\RoutingEffect.cs:34,4
0x34 in Xamarin.Forms.Element.set_EffectControlProvider at D:\a\1\s\Xamarin.Forms.Core\Element.cs:230,7
0x1C in Xamarin.Forms.Platform.iOS.EffectUtilities.RegisterEffectControlProvider at D:\a\1\s\Xamarin.Forms.Platform.iOS\EffectUtilities.cs:20,5
0x97 in Xamarin.Forms.Platform.iOS.PageRenderer.SetElement at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:140,4
0x16 in Xamarin.Forms.Platform.iOS.Platform.CreateRenderer at D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:227,4
0x14 in Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.SetPageRenderer at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRootRenderer.cs:438,4
0xA1 in Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.LoadRenderers at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRootRenderer.cs:238,5
0x78 in Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.ViewDidLoad at D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRootRenderer.cs:78,4
0x66 in UIKit.UIApplication.UIApplicationMain
0xB in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86,4
0x11 in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65,5
0x8 in MyApp.iOS.Application.Main at C:\MyApp.iOS\Main.cs:12,13
	at C:\MyApp.iOS\Main.cs(12)

@TheCaveOfWonders
Copy link
Author

hi @rmarinho please let me know if you still require a repro project or if the info I've given was enough, thanks.

@DeanFaizal
Copy link

A repro project would help with this investigation, thanks.

@TheCaveOfWonders
Copy link
Author

ExtremeFlyoutNavigation.zip

okay i've attached a repro project. You just have to switch between the pages back and forth and you'll see the exception thrown.

@Redth Redth removed the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label Mar 4, 2021
@jsuarezruiz
Copy link
Contributor

@stanios Does it happen on any specific device?. I have tried to reproduce on iPad 14.4 simulator without success.

@jsuarezruiz jsuarezruiz added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Mar 23, 2021
@TheCaveOfWonders
Copy link
Author

TheCaveOfWonders commented Mar 31, 2021

Yes i was able to repro on a 14.4 ipad simulator with the latest version of xamarin forms. Here's a gif showing it.
Bug

@Redth Redth removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Apr 5, 2021
@rachelkang
Copy link
Contributor

Confirming that I'm able to repro on the iPad 8th generation and iPad Pro 12.9" simulators on iOS 14.4. I'm also able to repro on an iPhone 7 device

I see the following exception when switching between flyout tabs:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ScrollViewRenderer'.
  at Foundation.NSObject.get_SuperHandle () [0x00012] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:394 
  at UIKit.UIView.RemoveGestureRecognizer (UIKit.UIGestureRecognizer gestureRecognizer) [0x00030] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIView.g.cs:1472 
  at MyCompany.iOS.Effects.TouchEffect.OnDetached () [0x0001b] in /Users/rachelkang/Downloads/ExtremeFlyoutNavigation/ExtremeFlyoutNavigation.iOS/Effects/TouchEffect.cs:45 

Another issue I noticed that could potentially be related is that switching between the tabs very quickly leaves only the color block in the UI.

Will need to investigate further

@rachelkang rachelkang added p/iOS 🍎 a/effects and removed s/unverified New report that has yet to be verified p/Android labels Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants