Forum Xamarin.iOS

"Cannot access disposed object" - Error when PopAsync

I'm currently facing the ObjectDisposedException when I PopAsync from a Pagerenderer to another. Here how to recreate the error using 3 pages:

Page "A": the renderer contains Camera capture elements;
Page "B": containing UITextviews, Labels and Images;
Page "C": the renderer called "LocationSearchRenderer" contains a PageRenderer + UITableViewController + UISearchResultsUpdating for searching location with a search bar.

From PageRenderer "A" I PushAsync to Page "B". Then from PageRenderer "B" I PushAsync to Page "C".
After selecting a location inside tableview in PageRenderer "C", I PopAsync to Page "B" with code below

Action action = async () =>
{
    await App.Current.MainPage.Navigation.PopAsync();
};

DismissViewController(true, action);

so far everything works just fine.
BUT when I try to PopAsync from "B" to "A" with a simple Navigation.PopAsync() the app crashes with

ObjectDisposedException
"Cannot access disposed object".
Object name: 'LocationSearchRenderer'

I googled for days but nothing seems to work. Saw many bug reports on github - bugzilla - stackoverflow - xamarinForums but I didn't find any solution.
Below you can find the sample Page code for page A, B and C, if may be useful:

public class PageX : ContentPage
{
    RelativeLayout layout;
        public NavBar bar;

    public PostDetailPage()
    {
        NavigationPage.SetHasNavigationBar(this, false);
        this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, App.HeightRes * 0.05);
            this.BackgroundColor = Color.Black;
        layout = new RelativeLayout();

        /// Create top bar.
            bool backButton = true;
                bool forwardButton = false;
                bar = new NavBar(backButton, forwardButton);
        bar.backButton.Clicked += BackButton_Clicked;

        /// Add bar to layout.
                ModelUtility.ConfigureSettingsLayout(layout, bar, null);

        /// Create Content.
        Content = layout;
    }

        async void BackButton_Clicked(object sender, EventArgs e)
        {
            await this.Navigation.PopAsync();
        }
}

I tried to move the PopAsync from Shared code to iOS but same result. The only thing that changed the result so far was using

await App.Current.MainPage.Navigation.PopAsync();

instead of

                            Action action = async () =>
                            {
                                await App.Current.MainPage.Navigation.PopAsync();
                            };

                            DismissViewController(true, action);

inside the Page "C". The crash from B to A didn't appear at first, but came out after the 2nd time I followed the path I described above.
Does anyone know a solution or workaround? Many thanks!!

Answers

  • DannyNDannyN USUniversity ✭✭

    Did you find a solution to this? I'm having the same problem and we aren't sure how to get around it. Thanks!

Sign In or Register to comment.