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

[Bug] System.ObjectDisposedException: 'Cannot access a disposed object. Object name: 'GroupableItemsViewController`1' #8394

Closed
ericbrunner opened this issue Nov 6, 2019 · 21 comments
Labels
s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛

Comments

@ericbrunner
Copy link

ericbrunner commented Nov 6, 2019

Description

On iOS a Shell App with CollectionView crashes. Android works.

Steps to Reproduce

  1. Login and GoTo //main/computers/root which loads the page with a CollectionView (computer:ComputersRootPage).
  2. Tap on TabBar to AccountPage (local:AccountPage)
  3. Tap on TabBar to computer:ComputersRootPage (like in 1st step)
  4. App crashes.

Shell AppShell.xaml structure:

<ShellItem Route="login">
    <ShellContent ContentTemplate="{DataTemplate local:LoginPage}"/>
</ShellItem>

<TabBar Route="main">
    <Tab Title="Computers" Icon="computers.png" Route="computers">
        <ShellContent ContentTemplate="{DataTemplate computer:ComputersRootPage}" 
                      Title="Root"
                      Route="root"
                      />
    </Tab>
    <Tab Title="Favorites" Icon="favorites.png">
        <ShellContent ContentTemplate="{DataTemplate local:FavoritesPage}" />
    </Tab>
    <Tab Title="Active" Icon="active.png">
        <ShellContent ContentTemplate="{DataTemplate local:ActivePage}" />
    </Tab>
    <Tab Title="Users" Icon="users.png">
        <ShellContent ContentTemplate="{DataTemplate local:UsersPage}" />
    </Tab>
    <Tab Title="Account" Icon="account.png">
        <ShellContent ContentTemplate="{DataTemplate local:AccountPage}" />
    </Tab>
</TabBar>

ComputersRootPage XAML structure

<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:forms="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
             Style="{StaticResource ContentPageBase}"
             mc:Ignorable="d"
             x:Class="Next.Remoted.Views.Computers.ComputersRootPage"
             Shell.NavBarIsVisible="True"
             x:Name="Self">

    <Shell.TitleView>
        <Label x:Name="TitleView"
               Opacity="0"
               HorizontalTextAlignment="Center"
               VerticalTextAlignment="Center"
               HorizontalOptions="CenterAndExpand"
               FontAttributes="Bold"
               TextColor="{StaticResource AppBlue}"
               Text="{Binding ComputersTitleText.Result}" />
    </Shell.TitleView>
    <ContentPage.ToolbarItems>
        <ToolbarItem IconImageSource="search" Command="{Binding SearchCommand}" />
    </ContentPage.ToolbarItems>


    <RefreshView IsRefreshing="{Binding IsRefreshing}"
                 Command="{Binding InitialLoadCommand}">
        <CollectionView x:Name="ComputersRootFolderView"
                        ItemsSource="{Binding RemotedEntries}"
                        SelectionMode="Single"
                        SelectionChanged="SelectableItemsView_OnSelectionChanged"
                        Scrolled="ItemsView_OnScrolled">
            <CollectionView.Header>
                <StackLayout HeightRequest="100">
                    <Label x:Name="HeaderTitle"
                           Text="{Binding Source={x:Reference Self}, Path=BindingContext.ComputersTitleText.Result}"
                           HorizontalOptions="CenterAndExpand"
                           Margin="0,20,0,0"
                           Style="{StaticResource ComputersPageLabel}" />
                    <Label
                        Text="{Binding Source={x:Reference Self}, Path=BindingContext.RemotedEntries.Count, StringFormat='{0}'}"
                        HorizontalTextAlignment="Center"
                        TextColor="{StaticResource AppLightBlue}"
                        Margin="5,10,0,10" />
                    <BoxView HeightRequest="1" HorizontalOptions="FillAndExpand" Color="{StaticResource AppBlue}" />
                </StackLayout>
            </CollectionView.Header>
            <CollectionView.EmptyView>
                <ActivityIndicator  IsRunning="True"
                                    Color="{StaticResource AppBlue}"
                                    BackgroundColor="{StaticResource AppDarkBlue}" />
            </CollectionView.EmptyView>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid Padding="0,5,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <forms:SvgCachedImage
                            Grid.Column="0"
                            WidthRequest="30"
                            HeightRequest="30"
                            Style="{StaticResource FfimageLandingStyle}"
                            Source="resource://Next.Remoted.Resources.folder_closed.svg" />

                        <Label
                            Grid.Column="1"
                            Style="{StaticResource ComputersPageLabel}"
                            Text="{Binding Name}" />

                        <forms:SvgCachedImage
                            Grid.Column="2"
                            WidthRequest="{OnPlatform Default=30,iOS=40}"
                            HeightRequest="{OnPlatform Default=30,iOS=40}"
                            Style="{StaticResource FfimageLandingStyle}"
                            Source="resource://Next.Remoted.Resources.more_static.svg">
                            <forms:SvgCachedImage.GestureRecognizers>
                                <TapGestureRecognizer
                                    Command="{Binding Path=BindingContext.ShowMoreCommand, Source={x:Reference Name=ComputersRootFolderView}}"
                                    CommandParameter="{Binding .}"
                                    NumberOfTapsRequired="1" />
                            </forms:SvgCachedImage.GestureRecognizers>
                        </forms:SvgCachedImage>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </RefreshView>
</ContentPage>

Expected Behavior

No crash.

Actual Behavior

iOS App crashes.

System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'GroupableItemsViewController`1'

Basic Information

XF SDK Version: 4.3.0.947036 (latest stable)
IDE: Visual Studio 2019
Platform Target Frameworks:
iOS: 13.1, 13.2 (Probbably other versions too)
App Type: Xamarin.Forms

@ericbrunner
Copy link
Author

@pauldipietro based on your last blog post https://devblogs.microsoft.com/xamarin/xamarin-forms-4-3-introducing-collectionview/
I developed my production app with the CollectionView. Because you wrote it is not experimental anymore. I appreciate your posts, but please take more care with such announcements. Now I have to revert back to ListView views.

@hartez
Copy link
Contributor

hartez commented Nov 16, 2019

@ericbrunner I'm trying to reproduce this error, but I'm not having much luck so far. Can you post a minimal repro project which demonstrates it?

@hartez hartez added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Nov 16, 2019
@hartez hartez moved this from New to Needs Info in Triage Nov 16, 2019
@kcrg
Copy link

kcrg commented Dec 3, 2019

Fix pls

@PureWeen
Copy link
Contributor

PureWeen commented Dec 7, 2019

@kcrg @ericbrunner

  • can you provide a repro? and/or provide a full stack trace? Though a repro would help us fix this super quick
  • test with the latest?

@ericbrunner
Copy link
Author

@PureWeen All that information is inside my comment from 6th of November. Create a new Xamarin.Forms Shell API without REST API Backend. Update the data-bindings in the XAML. Adjust the AppShell.xaml to the structure I posted. I will try to create such repo

@PureWeen
Copy link
Contributor

PureWeen commented Dec 7, 2019

@ericbrunner aw I had missed that there was an existing issue this linked to

So can we just close this one in favor of #8308 . ?

Seems like that one already has a repro and is confirmed

@ericbrunner
Copy link
Author

@PureWeen No you can't close this issue until solved. The other issue is different. There is mentioned that there is no issue on tabs. Well my filed issue is totally tabbar related / collectionview issue on iOS.

@PureWeen
Copy link
Contributor

PureWeen commented Dec 7, 2019

Sounds good! Though I'm fairly confident once that one is solved it'll fix this one :-)

In either case, a full stack trace would also be helpful

@ericbrunner
Copy link
Author

I'll create a repo tomorrow and upload it

@ericbrunner
Copy link
Author

@PureWeen

Ok i created a repo. In the meanwhile new Xamarin.Forms SDK versions were released. I updated to

Xamarin.Forms SDK: 4.4.0.936621-pre1

The iOS App doesn't crash now anymore, which is an improvement. But there are still related Debug Log outputs.

You can reproduce it when you pull down to refresh.

2019-12-08 07:57:00.943926+0100 ShellHotrestartAppTest.iOS[96794:8599051] [UICollectionView] Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). - will perform reloadData. UICollectionView instance: <UICollectionView: 0x7f983443b000; frame = (0 0; 414 725); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000e809c0>; layer = <CALayer: 0x60000073d100>; contentOffset: {0, -160}; contentSize: {414, 45}; adjustedContentInset: {160, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7f9832e35810>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7f9832e488c0>>; currentUpdate: [UICollectionViewUpdate 
- 0x7f9832e6ddf0: old:<UICollectionViewData: 0x6000039c0d20> new<UICollectionViewData: 0x60000393ed80> items:<(
    "I(0,0)"
)>]

ios_collectionview
ShellHotrestartAppTest.zip

@jsuarezruiz
Copy link
Contributor

The latest warnings should be fixed by: #7711

@ericbrunner
Copy link
Author

@jsuarezruiz In that case I close that issue

Triage automation moved this from Needs Info to Closed Dec 10, 2019
@FlatlinerDOA
Copy link

FlatlinerDOA commented Jan 8, 2020

Please re-open this issue, we receive this error Inserting items into an ObservableCollection on iOS Simulator, running Xamarin.Forms 4.4.0.991265

@samhouts samhouts removed this from Closed in Triage Jan 9, 2020
@furiozo
Copy link

furiozo commented Feb 10, 2020

Guys, we are experiencing the issue on iOS, on last stable version of XF related to navigation

2020-02-08 01:44:44.737620+0200 IRA.iOS[27782:209679] Unhandled managed exception: Cannot access a disposed object. Object name: 'ParentingViewController'. (System.ObjectDisposedException) at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/Foundation/NSObject2.cs:449 at UIKit.UIViewController.get_NavigationItem () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/UIViewController.g.cs:2303 at Xamarin.Forms.Platform.iOS.NavigationRenderer+<>c__DisplayClass76_0.<SetMasterLeftBarButton>b__0 (UIKit.UIImage icon) [0x0002c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:761 at Xamarin.Forms.Platform.iOS.ImageElementManager.ApplyNativeImageAsync (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.BindableProperty imageSourceProperty, System.Action1[T] onSet, System.Action1[T] onLoading, System.Threading.CancellationToken cancellationToken) [0x000fd] in D:\a \1\s\Xamarin.Forms.Platform.iOS\Renderers\ImageElementManager.cs:281 at Xamarin.Forms.Platform.iOS.NavigationRenderer.SetMasterLeftBarButton (UIKit.UIViewController containerController, Xamarin.Forms.MasterDetailPage masterDetailPage) [0x0007f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:747 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/Foundation/NSAction.cs:178 --- End of stack trace from previous location where exception was thrown ---

2020-02-08 01:27:04.306090+0200 IRA.iOS[24737:184880] Unhandled managed exception: Cannot access a disposed object. Object name: 'PrimaryToolbarItem'. (System.ObjectDisposedException) at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/Foundation/NSObject2.cs:449 at UIKit.UIBarButtonItem.set_Image (UIKit.UIImage value) [0x00033] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/UIBarButtonItem.g.cs:652 at Xamarin.Forms.Platform.iOS.ToolbarItemExtensions+PrimaryToolbarItem.UpdateIconAndStyle () [0x00031] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Extensions\ToolbarItemExtensions.cs:84 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynch ronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.17/src/Xamarin.iOS/Foundation/NSAction.cs:178 --- End of stack trace from previous location where exception was thrown ---

@g4mb10r
Copy link

g4mb10r commented Feb 12, 2020

@PureWeen @hartez Please fix this critical bug.

@lnaie
Copy link

lnaie commented Feb 15, 2020

I also get it randomly.

@bbenetskyy
Copy link
Contributor

bbenetskyy commented Jul 30, 2020

I can reproduce this 2 of 3 times 😢 with iOS v12.4 & Xamarin.Forms v4.7.0.1080, but in iOS v13.5 & v13.6 I can't reproduce it🧐

Update:

With version Xamarin.Forms 4.6.0.1180 this bug is not reproducible at iOS v12.4

@donatellijl
Copy link

I can reproduce with iOS 12.2 and Xamarin.Forms 4.7.0.1239

@FetFrumos
Copy link

I have this error. Xamarin Team, any news?

@urbancoderza
Copy link

I am also having this error on v4.8.0.1534

Last response to this issue was a year ago. Shocking.

@hartez
Copy link
Contributor

hartez commented Dec 10, 2020

Last response to this issue was a year ago. Shocking.

Not really, since the issue was closed a year ago.

The reproduction project posted by the opener of the issue still runs without crashing on the latest version of Forms. If you are experiencing an ObjectDisposedException it's likely coming from a different bug. Please open a new issue, and be sure to include relevant information about the circumstances in which your bug occurs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests