You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LoadStateAsync accepts a saved state containing null items, and the next SaveStateAsync throws NullReferenceException #60
NavigationState<T>'s constructor (Navigation/Models/NavigationState.cs:22-37) validates currentIndex but not the items themselves. A persisted file such as:
{"items":[null],"currentIndex":0}
deserializes successfully. JsonFilePersistenceProvider.LoadStateAsync returns it, and NavigationStack.LoadStateAsync returns true, leaving Count == 1 and Current == null.
The failure shows up later. After NavigateTo(b) and SaveStateAsync(), NavigationState.FromNavigationStack hits the null item in its FindIndex lambda:
System.NullReferenceException
at NavigationState`1.<FromNavigationStack>b__0 NavigationState.cs:76
at NavigationStack`1.SaveStateAsync NavigationStack.cs:136
This was reproduced with a temporary MSTest test.
Why it matters
A hand-edited or partly corrupted state file isn't rejected at load time, where the provider already turns invalid state into null and a clean false. Instead it is accepted, and every later save crashes the app with an unrelated-looking exception.
Suggested fix
In the NavigationState constructor, reject null entries:
if(itemList.Any(i =>iisnull))thrownewArgumentException("Navigation state items cannot be null.",nameof(items));
The provider already maps ArgumentException to a null result, so LoadStateAsync then returns false.
Acceptance: loading {"items":[null],"currentIndex":0} returns false and leaves the stack unchanged, with a test added.
Priority: Medium. A corrupted or hand-edited state file is accepted at load, and then every later save crashes with a NullReferenceException that seems unrelated. It needs bad input to trigger, but once triggered the app can't save.
Area / suggested assignee: The NavigationState<T> constructor in Models/NavigationState.cs (:22-37). Maintainer: @matt-edmondson.
Next steps: Reject null items in the constructor with an ArgumentException, which the provider already turns into a false load. Add the {"items":[null],"currentIndex":0} test and check that the stack is left unchanged.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
NullReferenceExceptionthat seems unrelated. It needs bad input to trigger, but once triggered the app can't save.NavigationState<T>constructor inModels/NavigationState.cs(:22-37). Maintainer: @matt-edmondson.Next steps: Reject null items in the constructor with an
ArgumentException, which the provider already turns into afalseload. Add the{"items":[null],"currentIndex":0}test and check that the stack is left unchanged.Generated by Claude Code