PrismLibrary/Prism · error · ArgumentNullException
Resources.NavigationModeNotAvailable
Error message
Resources.NavigationModeNotAvailable
What it means
GetNavigationMode reads the NavigationMode value from the internal navigation parameters. If the NavigationMode key has never been added to the parameters (i.e. this extension is called outside of an actual Prism navigation operation), the method throws ArgumentNullException wrapping the Resources.NavigationModeNotAvailable message. The library throws it because NavigationMode is an internal bookkeeping value only present during real navigation calls.
Solutions
- Only call GetNavigationMode when the parameters actually came from a Prism navigation (INavigationAware hooks during NavigateAsync/GoBackAsync).
- Check internalParams.ContainsKey(KnownInternalParameters.NavigationMode) (or use TryGetValue) before reading the value.
- In tests, seed the parameters with the internal key: parameters.Add(KnownInternalParameters.NavigationMode, NavigationMode.New) via INavigationParametersInternal.
- For the root/initial page, treat missing mode as NavigationMode.New instead of throwing.
Example fix
// before
var mode = parameters.GetNavigationMode();
// after
var internalParams = (INavigationParametersInternal)parameters;
var mode = internalParams.ContainsKey(KnownInternalParameters.NavigationMode)
? internalParams.GetValue<NavigationMode>(KnownInternalParameters.NavigationMode)
: NavigationMode.New; Defensive patterns
Strategy: type-guard
Validate before calling
var internalParams = (INavigationParametersInternal)parameters;
if (!internalParams.ContainsKey(KnownInternalParameters.NavigationMode))
return; // or default to NavigationMode.New Type guard
bool TryGetNavigationMode(INavigationParameters p, out NavigationMode mode)
{
var i = (INavigationParametersInternal)p;
if (i.ContainsKey(KnownInternalParameters.NavigationMode))
{ mode = i.GetValue<NavigationMode>(KnownInternalParameters.NavigationMode); return true; }
mode = default; return false;
} Try / catch
try { var mode = parameters.GetNavigationMode(); }
catch (ArgumentNullException) { /* outside a Prism navigation; use default mode */ } Prevention
- Only call GetNavigationMode inside INavigationAware hooks triggered by Prism navigation calls
- Seed NavigationParameters in tests with the internal NavigationMode key
- Treat the root page (no navigation) as NavigationMode.New by default
When it happens
Trigger: Calling parameters.GetNavigationMode() on INavigationParameters that were created manually (new NavigationParameters()) or received outside a Prism-driven navigation (e.g. in OnNavigatedFrom on pages pushed by raw Xamarin/Maui Shell navigation, or in unit tests constructing parameters by hand).
Common situations: Developers inspecting navigation mode in ViewModel lifecycle hooks when the page was created without Prism's navigation service; testing ViewModels with hand-built NavigationParameters; calling the extension in OnNavigatingTo for the very first page created by the app container rather than a navigation call.
Related errors
- Invalid Scope provided. The current scope Page Accessor…
- NavigationException.IConfirmNavigationReturnedFalse
- NavigationException.GoBackRequiresNavigationPage
- The Page is null.
- Invalid Tab Name
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/757f2763d334794e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/NavigationParametersExtensions.cs:13
using Prism.Properties;
namespace Prism.Navigation;
public static class NavigationParametersExtensions
{
public static NavigationMode GetNavigationMode(this INavigationParameters parameters)
{
var internalParams = (INavigationParametersInternal)parameters;
if (internalParams.ContainsKey(KnownInternalParameters.NavigationMode))
return internalParams.GetValue<NavigationMode>(KnownInternalParameters.NavigationMode);
throw new System.ArgumentNullException(Resources.NavigationModeNotAvailable);
}
internal static INavigationParametersInternal GetNavigationParametersInternal(this INavigationParameters parameters)
{
return (INavigationParametersInternal)parameters;
}
}
View on GitHub (pinned to 358118cd64)