{"record":{"id":"b766ac72aaa80070","repo":"PrismLibrary/Prism","slug":"argumentnullexception-nameof-navigationcontext","errorCode":null,"errorMessage":"ArgumentNullException(nameof(navigationContext))","messagePattern":"ArgumentNullException\\(nameof\\(navigationContext\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Navigation/Regions/RegionNavigationEventArgs.cs","lineNumber":16,"sourceCode":"using System;\n\nnamespace Prism.Navigation.Regions\n{\n    /// <summary>\n    /// EventArgs used with the Navigated event.\n    /// </summary>\n    public class RegionNavigationEventArgs : EventArgs\n    {\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"RegionNavigationEventArgs\"/> class.\n        /// </summary>\n        /// <param name=\"navigationContext\">The navigation context.</param>\n        public RegionNavigationEventArgs(NavigationContext navigationContext)\n        {\n            NavigationContext = navigationContext ?? throw new ArgumentNullException(nameof(navigationContext));\n        }\n\n        /// <summary>\n        /// Gets the navigation context.\n        /// </summary>\n        /// <value>The navigation context.</value>\n        public NavigationContext NavigationContext { get; }\n\n        /// <summary>\n        /// Gets the navigation URI\n        /// </summary>\n        /// <value>The URI.</value>\n        /// <remarks>\n        /// This is a convenience accessor around NavigationContext.Uri.\n        /// </remarks>\n        public Uri Uri => NavigationContext.Uri;\n    }\n}","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Navigation/Regions/RegionNavigationEventArgs.cs#L1-L34","documentation":"The RegionNavigationEventArgs constructor requires a NavigationContext and throws ArgumentNullException when null is passed. Every region navigation event argument must carry the context that describes the navigation.","triggerScenarios":"Constructing RegionNavigationEventArgs directly (e.g. raising the region's NavigationService events manually or in tests) and passing null instead of an active NavigationContext.","commonSituations":"Custom INavigationService implementations or unit test mocks that raise RegionNavigation events without a context; refactoring where context is only available after an async boundary.","solutions":["Only construct the event args with a valid NavigationContext obtained from the navigation service","In custom services, guard against null context before raising events","In tests, build a NavigationContext via a NavigationJournal/Uri rather than passing null"],"exampleFix":"// before\neventArgs = new RegionNavigationEventArgs(null);\n// after\nvar ctx = new NavigationContext(navigationService, new Uri(\"/View\", UriKind.Relative));\neventArgs = new RegionNavigationEventArgs(ctx);","handlingStrategy":"type-guard","validationCode":"if (navigationContext == null) return; // or throw InvalidOperationException with context","typeGuard":"bool IsValid(RegionNavigationEventArgs a) => a?.NavigationContext != null;","tryCatchPattern":"try { RaiseNavEvent(new RegionNavigationEventArgs(ctx)); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"navigationContext\") { log.Error(\"Navigation raised without context\"); }","preventionTips":["Never construct navigation event args manually unless implementing a custom INavigationService","Always derive event args from the current navigation context"],"tags":["prism","navigation","argumentnull","event-args"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}