Skip to content

Commit 2a154dc

Browse files
Fix: Avoid NullReferenceException in NavigationToolbarViewModel (#17610)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent 316d783 commit 2a154dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,14 @@ public async Task PopulateOmnibarSuggestionsForPathMode()
942942
void AddNoResultsItem()
943943
{
944944
PathModeSuggestionItems.Clear();
945+
946+
// Use null-safe access to avoid NullReferenceException during app lifecycle transitions
947+
var workingDirectory = string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
948+
? Constants.UserEnvironmentPaths.HomePath
949+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
950+
945951
PathModeSuggestionItems.Add(new(
946-
ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory,
952+
workingDirectory,
947953
Strings.NavigationToolbarVisiblePathNoResults.GetLocalizedResource()));
948954
}
949955
}

0 commit comments

Comments
 (0)