System.ObjectDisposedException Can't access disposed Xamarin.Forms.Platform.Android.ImageRenderer

Hi Xamarian,

Hope you all are doing good.

Please help me out . I'm facing one issue with grouped Listview . i.e.

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.ImageRenderer'.

Below is my UI code


<ListView.Behaviors>

                </b:EventToCommandBehavior>
            </ListView.Behaviors>
            <ListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell >
                        <ViewCell.Height>
                            <OnPlatform x:TypeArguments="x:Double" iOS="60"/>
                        </ViewCell.Height>
                        <Frame  IsClippedToBounds="True"
                            HasShadow="True"
                            Margin="{OnPlatform Android='0,3',iOS='0,0,0,6'}"
                            Padding="0"
                            CornerRadius="3"
                            BackgroundColor="{StaticResource AppSubThemeColor}">
                            <Frame IsClippedToBounds="True"
                               HasShadow="True"
                               BorderColor="{Binding GroupSelectedColor}"
                               BackgroundColor="{Binding GroupSelectedColor}"
                               Padding="10"
                               CornerRadius="0"
                               Margin="0">
                                <StackLayout Spacing="0"
                                     Orientation="Horizontal">
                                    <!--<ff:CachedImage x:Name="ffStateIicon"
                                            HeightRequest="20"
                                            WidthRequest="20"
                                            Margin="5"
                                            VerticalOptions="CenterAndExpand"
                                            HorizontalOptions="Start"
                                            Source="{Binding StateIcon}"/>-->
                                    <Image x:Name="ffStateIicon"
                                            HeightRequest="20"
                                            WidthRequest="20"
                                            Margin="5"
                                            VerticalOptions="CenterAndExpand"
                                            HorizontalOptions="Start"
                                            Source="{Binding StateIcon}"/>
                                    <Label Text="{Binding TitleWithItemCount}" 
                                           HorizontalOptions="StartAndExpand"
                                           HorizontalTextAlignment="Start"
                                           VerticalOptions="Center"
                                           TextColor="Black"
                                           Style="{StaticResource Key=lblCardValue}"
                                          >
                                    </Label>
                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer 
                                        Command="{Binding Source={x:Reference ProductFilterPage}, 
                                        Path=BindingContext.FacetSelectedCommand}" 
                                        NumberOfTapsRequired="1"
                                        CommandParameter="{Binding .}"/>
                                    </StackLayout.GestureRecognizers>
                                </StackLayout>
                                <!--,Converter={StaticResource NameConverter}-->
                            </Frame>
                        </Frame>
                    </ViewCell>
                </DataTemplate>
            </ListView.GroupHeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Frame  IsClippedToBounds="True"
                            HasShadow="True"
                            Margin="0"
                            Padding="10"
                            CornerRadius="0"
                            BackgroundColor="#FFFFFF">
                            <StackLayout Spacing="0"
                                     Orientation="Horizontal">
                                <!--<ff:CachedImage x:Name="ffCheck"
                                            HeightRequest="30"
                                            WidthRequest="30"
                                            Margin="5"
                                            VerticalOptions="CenterAndExpand"
                                            HorizontalOptions="Start"
                                            Source="{Binding ImgSource}"/>-->
                                <Image x:Name="ffCheck"
                                            HeightRequest="30"
                                            WidthRequest="30"
                                            Margin="5"
                                            VerticalOptions="CenterAndExpand"
                                            HorizontalOptions="Start"
                                            Source="{Binding ImgSource}"/>
                                <Label Text="{Binding FacetValue}"
                                   HorizontalOptions="StartAndExpand"
                                   HorizontalTextAlignment="Start"
                                   VerticalOptions="Center"
                                   >
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="{Binding FacetValue}" Style="{StaticResource Key=spnNormal}"/>
                                            <Span Text="{Binding ValueCount}" Style="{StaticResource Key=spnNormal}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>
                            </StackLayout>
                        </Frame>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

On clicking item i'm changing image from checked to unchecked and vice versa. sometime i'm getting crash on scroll and sometime on item tapped.
Below is my stack traces

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
View.get_Context ()
Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1307
Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:599
VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:788
Image.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\Image.cs:64
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:771
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:653
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:711
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:199
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:124
StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:57
Layout.UpdateChildrenLayout () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:264
Layout.OnSizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
VisualElement.SizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:793
Layout+<>c.b__45_0 () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.44(intptr,intptr)

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    You can look into this Bug: https://bugzilla.xamarin.com/show_bug.cgi?id=55621

    And you can try to change the CachingStrategy to RecycleElement, as suggested in that bug report.

  • Alice_XamarinGuyAlice_XamarinGuy Member ✭✭
    edited March 26

    Hi jezh
    Thanks for showing interest and replying.

                              Grid.Row="1"
                              VerticalOptions="FillAndExpand"
                              HasUnevenRows="True" 
                              Margin="10,10,10,0" 
                              CachingStrategy = "RecycleElement"
                              SeparatorVisibility="None"
                              IsGroupingEnabled="True"
                              GroupDisplayBinding="{Binding FacetName}"
                              SeparatorColor="{StaticResource AppSecondaryTextColor}"                      
                              ItemsSource="{Binding FacetList}"
    

    Actually i'm using RecycleElement , My full code was not there from top initial content is missing

  • jezhjezh Member, Xamarin Team Xamurai

    Could you please post a basic demo so that we can test with it?

  • M0BilalM0Bilal USMember ✭✭

    I am also facing the same issue, any update on this?

Sign In or Register to comment.