{"record":{"id":"21ce3e468af1aa20","repo":"dotnet/wpf","slug":"sr-absoluteurionly","errorCode":null,"errorMessage":"SR.AbsoluteUriOnly","messagePattern":"SR\\.AbsoluteUriOnly","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs","lineNumber":870,"sourceCode":"            // TFS  - Launching a navigation from the Navigating event handler causes reentrancy.\n            // For more info, see WebBrowser.LastNavigation. Here we generate a new navigation identifier which\n            // is used to detect reentrant calls during handling of the Navigating event.\n            LastNavigation = Guid.NewGuid();\n\n            // When source set to null or navigating to stream/string, we navigate to \"about:blank\" internally.\n            if (source == null)\n            {\n                NavigatingToAboutBlank = true;\n                source = new Uri(AboutBlankUriString);\n            }\n            else\n            {\n                CleanInternalState();\n            }\n\n            if (!source.IsAbsoluteUri)\n            {\n                throw new ArgumentException(SR.AbsoluteUriOnly, nameof(source));\n            }\n\n            // Resolve Pack://siteoforigin.\n            if (PackUriHelper.IsPackUri(source))\n            {\n                source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);\n            }\n\n            // figure out why BrowserNavConstants.NewWindowsManaged does not work.\n            object flags = (object)null; // UnsafeNativeMethods.BrowserNavConstants.NewWindowsManaged;\n\n            // Fix for inability to navigate to a URI containing invalid UTF-8 sequences\n            // BindUriHelper.UriToString does use Uri.GetComponents with the UriFormat.SafeUnescaped flag passed in,\n            // causing invalid UTF-8 sequences to get dropped, resulting in a strictly speaking valid URI but for\n            // some websites this causes breakage. Therefore we allow ignoring this treatment by means of string-\n            // based overloads for the public Navigate methods, creating a Uri internally and using AbsoluteUri\n            // to get back the URI string to feed in to the WebOC in its original form. WinForms has a similar\n            // set of overloads to enable this scenario.","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs#L852-L888","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nbrowser.Navigate(new Uri(\"example.com/page\"));\n// after\nbrowser.Navigate(new Uri(\"https://example.com/page\", UriKind.Absolute));","handlingStrategy":"validation","validationCode":"public static void NavigateSafe(this WebBrowser wb, Uri uri)\n{\n    if (uri == null) throw new ArgumentNullException(nameof(uri));\n    if (!uri.IsAbsoluteUri)\n        throw new ArgumentException(\"URI must be absolute\", nameof(uri));\n    wb.Navigate(uri);\n}","typeGuard":"static bool IsNavigable(Uri u) => u != null && u.IsAbsoluteUri;","tryCatchPattern":"try { browser.Navigate(uri); } catch (ArgumentException ex) when (ex.ParamName == \"source\") { Log.Error($\"Navigation aborted: '{uri}' is not an absolute URI.\"); }","preventionTips":["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."],"tags":["wpf","webbrowser","uri","argument"],"backgroundTag":"invalid-url-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}