dotnet/wpf · error · ArgumentException
SR.AbsoluteUriOnly
Error message
SR.AbsoluteUriOnly
What it means
WebBrowser.Navigate(Uri) requires an absolute URI. When the source Uri's IsAbsoluteUri is false, the method throws ArgumentException because a relative URI cannot be resolved to an externally visible navigation target without a base. This is an eager argument-validation failure inside DoNavigate, reached via Navigate.
Solutions
- Ensure the Uri is absolute: new Uri("https://example.com/page.html") or new Uri(str, UriKind.Absolute).
- Resolve relative URIs against a base before navigating: new Uri(baseUri, relativeUri).
- Use the Navigate(string) overload with a fully qualified URL string.
- Validate Uri.IsAbsoluteUri before calling Navigate and surface a friendly message.
Example fix
// before
browser.Navigate(new Uri("example.com/page"));
// after
browser.Navigate(new Uri("https://example.com/page", UriKind.Absolute)); Defensive patterns
Strategy: validation
Validate before calling
public static void NavigateSafe(this WebBrowser wb, Uri uri)
{
if (uri == null) throw new ArgumentNullException(nameof(uri));
if (!uri.IsAbsoluteUri)
throw new ArgumentException("URI must be absolute", nameof(uri));
wb.Navigate(uri);
} Type guard
static bool IsNavigable(Uri u) => u != null && u.IsAbsoluteUri;
Try / catch
try { browser.Navigate(uri); } catch (ArgumentException ex) when (ex.ParamName == "source") { Log.Error($"Navigation aborted: '{uri}' is not an absolute URI."); } Prevention
- Always construct URIs with UriKind.Absolute and an explicit scheme.
- Never assume 'host/path' strings are URLs — they lack the scheme.
- Resolve relative URIs against a known base before navigating.
- Validate Uri.IsAbsoluteUri in a shared navigation helper.
When it happens
Trigger: Calling webBrowser.Navigate(new Uri("page.html")) or Navigate(someRelativeUri); passing a Uri built from a string without a scheme; navigating with a Uri created via new Uri(relativeString, UriKind.Relative).
Common situations: Hard-coding paths like 'www.example.com' (missing scheme), reading URLs from config without scheme, constructing URIs by string concatenation that drop the 'http://' prefix.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- SR.Effect_SourceUriMustBeFileOrPack
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote"…
- SR.NonPackSooAbsoluteUriNotAllowed
- SR.UriNotAbsolute
- UriMustBeAbsolute
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/21ce3e468af1aa20.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs:870
// TFS - Launching a navigation from the Navigating event handler causes reentrancy.
// For more info, see WebBrowser.LastNavigation. Here we generate a new navigation identifier which
// is used to detect reentrant calls during handling of the Navigating event.
LastNavigation = Guid.NewGuid();
// When source set to null or navigating to stream/string, we navigate to "about:blank" internally.
if (source == null)
{
NavigatingToAboutBlank = true;
source = new Uri(AboutBlankUriString);
}
else
{
CleanInternalState();
}
if (!source.IsAbsoluteUri)
{
throw new ArgumentException(SR.AbsoluteUriOnly, nameof(source));
}
// Resolve Pack://siteoforigin.
if (PackUriHelper.IsPackUri(source))
{
source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
}
// figure out why BrowserNavConstants.NewWindowsManaged does not work.
object flags = (object)null; // UnsafeNativeMethods.BrowserNavConstants.NewWindowsManaged;
// Fix for inability to navigate to a URI containing invalid UTF-8 sequences
// BindUriHelper.UriToString does use Uri.GetComponents with the UriFormat.SafeUnescaped flag passed in,
// causing invalid UTF-8 sequences to get dropped, resulting in a strictly speaking valid URI but for
// some websites this causes breakage. Therefore we allow ignoring this treatment by means of string-
// based overloads for the public Navigate methods, creating a Uri internally and using AbsoluteUri
// to get back the URI string to feed in to the WebOC in its original form. WinForms has a similar
// set of overloads to enable this scenario.View on GitHub (pinned to 81131a70a4)