{"record":{"id":"b786e24ced07cb77","repo":"PrismLibrary/Prism","slug":"candidatenavigationcontract","errorCode":null,"errorMessage":"candidateNavigationContract","messagePattern":"candidateNavigationContract","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs","lineNumber":109,"sourceCode":"\n        var candidateTargetContract = UriParsingHelper.EnsureAbsolute(navigationContext.Uri).AbsolutePath;\n        candidateTargetContract = candidateTargetContract.TrimStart('/');\n        return Uri.UnescapeDataString(candidateTargetContract);\n    }\n\n    /// <summary>\n    /// Returns the set of candidates that may satisfy this navigation request.\n    /// </summary>\n    /// <param name=\"region\">The region containing items that may satisfy the navigation request.</param>\n    /// <param name=\"candidateNavigationContract\">The candidate navigation target as determined by <see cref=\"GetContractFromNavigationContext\"/></param>\n    /// <returns>An enumerable of candidate objects from the <see cref=\"IRegion\"/></returns>\n    protected virtual IEnumerable<VisualElement> GetCandidatesFromRegion(IRegion region, string candidateNavigationContract)\n    {\n        ArgumentNullException.ThrowIfNull(region);\n\n        if (string.IsNullOrEmpty(candidateNavigationContract))\n        {\n            throw new ArgumentNullException(nameof(candidateNavigationContract));\n        }\n\n        var contractCandidates = RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, candidateNavigationContract);\n\n        if (!contractCandidates.Any())\n        {\n            var registry = region.Container().Resolve<IRegionNavigationRegistry>();\n            var registration = registry.Registrations.FirstOrDefault(x => x.Type == ViewType.Region && (x.Name == candidateNavigationContract || x.View.Name == candidateNavigationContract || x.View.FullName == candidateNavigationContract));\n            if (registration is not null)\n            {\n                RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, registration.View.FullName);\n            }\n\n            return [];\n        }\n\n        return contractCandidates;\n    }","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs#L91-L127","documentation":"RegionNavigationContentLoader.GetCandidatesFromRegion throws ArgumentNullException when candidateNavigationContract is null or empty (the 'region' parameter is additionally guarded by ArgumentNullException.ThrowIfNull). It needs the contract name to match candidate views already present in the region.","triggerScenarios":"Calling GetCandidatesFromRegion with an empty string or null contract — e.g. regionManager.RequestNavigation with an empty name, or a custom content loader invoked with an unpopulated navigation URI segment.","commonSituations":"Navigation target name built dynamically from bindings that evaluated to empty; custom IRegionNavigationContentLoader implementations passing through unparsed URIs; RequestNavigation called before the navigation path was computed.","solutions":["Pass a non-empty view/contract name to the navigation API","Validate/trim the navigation string before RequestNavigation","Fix the source of the empty contract (binding, route parsing)","When writing a custom content loader, guard the contract parameter yourself"],"exampleFix":"// before\nregionManager.RequestNavigate(new Uri(string.Empty, UriKind.Relative));\n// after\nif (string.IsNullOrWhiteSpace(targetName)) return;\nregionManager.RequestNavigate(targetName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(contract)) return Enumerable.Empty<VisualElement>();\nvar candidates = loader.GetCandidatesFromRegion(region, contract);","typeGuard":"bool HasContract(string? c) => !string.IsNullOrWhiteSpace(c);","tryCatchPattern":"try { var cands = loader.GetCandidatesFromRegion(region, contract); }\ncatch (ArgumentNullException ex) { logger.Warn(ex, \"Empty navigation contract\"); }","preventionTips":["Validate navigation names before RequestNavigate","Guard custom content loaders for empty contracts","Trace URI parsing to ensure the contract segment is populated","Never derive navigation targets from unvalidated bindings"],"tags":["null-argument","regions","navigation"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}