PrismLibrary/Prism · error · InvalidOperationException
The constructed URI has a relative back operator after a…
Error message
The constructed URI has a relative back operator after a new Navigation Segment which is not supported - '{uri}'. What it means
BuildUri also rejects a URI where a '..' back operator appears AFTER a real navigation segment, since .NET MAUI/Prism navigation cannot pop and then descend within a single URI in that order. It throws InvalidOperationException identifying the constructed URI.
Solutions
- Reorder segments: put all RelativeBack() calls first, then the page segments to descend into: RelativeBack().AddSegment("DetailPage").
- Split navigation into two calls if you need pop-then-push semantics (GoBackAsync then NavigateAsync).
- Validate the segment list before building: reject any '..' appearing after a non-'..' segment.
Example fix
// before
navigationService.CreateBuilder().AddSegment("DetailPage").RelativeBack().NavigateAsync(); // back after segment
// after
navigationService.CreateBuilder().RelativeBack().AddSegment("DetailPage").NavigateAsync(); // back first Defensive patterns
Strategy: validation
Validate before calling
bool backAfterSegment = false; bool hasPage = false;
foreach (var s in segments)
{
if (s == "..") { if (hasPage) { backAfterSegment = true; break; } }
else hasPage = true;
}
if (backAfterSegment) throw new InvalidOperationException("All '..' segments must precede page segments."); Try / catch
try
{
await navigationService.NavigateAsync(uri);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("after a new Navigation Segment"))
{
logger.LogError(ex, "Navigation segments out of order: {Uri}", uri);
} Prevention
- Always build URIs as [.. ']* followed by page segments.
- Use RelativeBack() extension at the start of the chain, then AddSegment calls.
- Split pop-then-push needs into GoBackAsync() + NavigateAsync() calls.
When it happens
Trigger: Building segments in the order [page segment, '..', ...] — e.g. AddSegment("DetailPage").RelativeBack() — then calling NavigateAsync(); the loop detects hasNonBackSegment followed by a '..' segment.
Common situations: Misunderstanding that RelativeBack must precede new segments (it walks up first); assembling segments from user input or config in the wrong order; refactoring that appends a back step after navigating deeper.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The constructed URI contains one or more relative back…
- The generated URI has one or more relative back operators…
- Cannot process an absolute Navigation Uri when navigating…
- source
- uri
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/4468d8711ae4298b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs:118
internal Uri BuildUri()
{
var uri = (_absoluteNavigation ? "/" : string.Empty) +
string.Join("/", _uriSegments.Select(x => x.Segment));
if(uri.Contains("../"))
{
if (_absoluteNavigation)
throw new InvalidOperationException("The generated URI has one or more relative back operators and was marked as an absolute path. This is not supported.");
var segments = uri.Split('/');
if (!segments.Any(x => x != ".."))
throw new InvalidOperationException($"The constructed URI contains one or more relative back operators, but contains no other navigation segments - '{uri}'.");
var hasNonBackSegment = false;
for(int i = 0; i < segments.Length; i++)
{
if (hasNonBackSegment && segments[i] == "..")
throw new InvalidOperationException($"The constructed URI has a relative back operator after a new Navigation Segment which is not supported - '{uri}'.");
else if (segments[i] != "..")
hasNonBackSegment = true;
}
}
return UriParsingHelper.Parse(uri);
}
}
View on GitHub (pinned to 358118cd64)