dotnet/wpf · error · ArgumentException
SR.HyperLinkTargetNotFound
Error message
SR.HyperLinkTargetNotFound
What it means
NavigationService.OnRequestNavigate() handles a Hyperlink click; when the hyperlink's target (NavigateUri) cannot be resolved — the handler does not produce a navigation target — it throws ArgumentException with HyperLinkTargetNotFound. It signals that the URI the hyperlink points at has no resolvable destination at that point.
Solutions
- Use an absolute pack URI, e.g. pack://application:,,,/MyPage.xaml, instead of an ambiguous relative URI
- Ensure the hyperlink is hosted in a Frame or NavigationWindow that can resolve the target
- Verify the NavigateUri and TargetName spellings and that the target resource exists in the assembly
- Handle NavigationService.NavigationFailed to catch resolution problems gracefully
Example fix
<!-- before --> <TextBlock><Hyperlink NavigateUri="Page2.xaml">Go</Hyperlink></TextBlock> <!-- after --> <TextBlock><Hyperlink NavigateUri="pack://application:,,,/MyApp;component/Page2.xaml">Go</Hyperlink></TextBlock>
Defensive patterns
Strategy: validation
Validate before calling
bool resolvable = hyperlink.NavigateUri != null && hyperlink.NavigateUri.IsAbsoluteUri;
if (!resolvable) hyperlink.NavigateUri = new Uri("pack://application:,,,/TargetPage.xaml", UriKind.Absolute); Type guard
bool HasResolvableTarget(Hyperlink h) =>
h?.NavigateUri != null && h.NavigateUri.ToString().StartsWith("pack://"); Try / catch
try { frame.NavigationService.Navigate(hyperlink.NavigateUri); }
catch (ArgumentException ex) when (ex.Message.Contains("target")) {
// fall back to default page or show message
} Prevention
- Use absolute pack URIs for NavigateUri
- Host hyperlinks inside Frame/NavigationWindow
- Subscribe to NavigationFailed to log unresolved URIs early
When it happens
Trigger: Clicking a Hyperlink whose NavigateUri is null/empty or whose target (e.g. relative pack URI or named element/fragment) cannot be resolved by the hosting NavigationService in OnRequestNavigate.
Common situations: Relative pack URIs in a page hosted without a proper Application/Frame context; typos in NavigateUri; hyperlinks placed in surfaces (e.g. certain popups/controls) without navigation container; missing base URI for relative resolution.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- Cannot read Page properties because it is not in a tree…
- SR.DocumentReferenceNotFound
- SR.EnumeratorVersionChanged
- SR.FailedToConvertResource
- SR.Format(SR.CannotNavigateToApplicationResourcesInWebBrowse…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cbf67f69e5c07cdb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs:205
{
if (inSameThread)
{
navigator.Navigate(bpu);
}
else
{
((DispatcherObject)navigator).Dispatcher.BeginInvoke(
DispatcherPriority.Send,
(DispatcherOperationCallback)delegate(object unused)
{
return navigator.Navigate(bpu);
},
null);
}
}
else
{
throw new System.ArgumentException(SR.HyperLinkTargetNotFound);
}
}
// Tests if two uris resolve to the same Uri. The Uri fragments are also
// compared. Neither comparison is case sensitive.
private static bool IsSameUri(Uri baseUri, Uri a, Uri b, bool withFragment)
{
if (object.ReferenceEquals(a, b)) // also handles both null
{
return true;
}
if (a == null || b == null)
{
return false;
}
Uri aResolved = BindUriHelper.GetResolvedUri(baseUri, a);
Uri bResolved = BindUriHelper.GetResolvedUri(baseUri, b);View on GitHub (pinned to 81131a70a4)