Cannot access a disposed object. Object name: 'PrimaryToolbarItem'.

Omair Al Hamid 21 Reputation points
2020-12-13T22:55:10.223+00:00

I am getting above exception when I try to Navigate to a page or Go Back while running App on iOS. It works perfectly fine on Android.

I believe it started happening since I added Shell in my App.

If I comment the Toolbar Item then it starts working.

<!--<ContentPage.ToolbarItems>
<ToolbarItem x:Name="refresh" IconImageSource="{helpers:ImageResource XamarinCMF.images.ic_menu_refresh.png}"
Command="{Binding GetNearestCommand}"></ToolbarItem>
</ContentPage.ToolbarItems>-->

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2020-12-16T10:45:32.903+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Cannot access a disposed object. Object name: 'PrimaryToolbarItem'.

    Hi, I tested the code in a Shell project on iOS platform and faced the same issue. The Embedded works fine for the normal image in the contentPage, but it will crash for the ToolbarItem. You could report this issue to the product team on github for a solution.

    If you want to place the images to shared project and load it, you could use ImageSource.FromFile() instead.

       toolbar_item.IconImageSource = ImageSource.FromFile("test.png");  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful