0

Currently in the process of trying to build a simple app, I want to create an object using Sqlite and then navigate back to overview so I can see the created item in my listview.

Creating the objects and storing works fine, but I'm getting a System.ArgumentOutOfRangeException when trying to navigate back to the overview.

The weird thing is, that when I restart the app my model is correctly shown in the table. Meaning that it did in fact get created.

Code as follows:


// Code in viewModel
async Task Store()
{
    // Do some db operations
    await Shell.Current.GoToAsync($"/dashboard");
}


It works fine the first time I navigate but after the second time I will get the following error:

\*\*System.ArgumentOutOfRangeException:\*\* 'Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index'

I've tried to put the navigation part in a try/catch block but with no success.

I don't understand why it works the first time but not the second time around.

Gianni
  • 1
  • 1
  • 1
    The exception stack trace should show the exact line causing it. Most likely there is something in OnAppearing causing it – Jason Jan 21 '23 at 18:06
  • *"I've tried to put the navigation part in a try/catch block but with no success."* Because there is nothing wrong with the navigation. Problem is in the dashboard page. *"I don't understand why it works the first time but not the second time around."* Either because it is already on the nav stack, or because there is something on the page that doesn't like being done a second time, or, IIRC, an app shell page isn't "created from scratch" the second time; I think it re-uses the page object, so doesn't run constructor again. `OnAppearing` is the first method run. – ToolmakerSteve Jan 21 '23 at 18:54

0 Answers0