{"record":{"id":"f3af2e271ebf1e01","repo":"dotnet/wpf","slug":"sr-format-sr","errorCode":null,"errorMessage":"SR.Format(SR.CannotNavigateToApplicationResourcesInWebBrowser, packUri)","messagePattern":"SR\\.Format\\(SR\\.CannotNavigateToApplicationResourcesInWebBrowser, packUri\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Navigation/BaseUriHelper.cs","lineNumber":371,"sourceCode":"                }\n            }\n\n            return sUri;\n        }\n\n        internal static Uri ConvertPackUriToAbsoluteExternallyVisibleUri(Uri packUri)\n        {\n            Invariant.Assert(packUri.IsAbsoluteUri && string.Equals(packUri.Scheme, PackAppBaseUri.Scheme, StringComparison.OrdinalIgnoreCase));\n\n            Uri relative = MakeRelativeToSiteOfOriginIfPossible(packUri);\n\n            if (! relative.IsAbsoluteUri)\n            {\n                return new Uri(SiteOfOriginContainer.SiteOfOrigin, relative);\n            }\n            else\n            {\n               throw new InvalidOperationException(SR.Format(SR.CannotNavigateToApplicationResourcesInWebBrowser, packUri));\n            }\n        }\n\n        // If a Uri is constructed with a legacy path such as c:\\foo\\bar then the Uri\n        // object will not correctly resolve relative Uris in some cases.  This method\n        // detects and fixes this by constructing a new Uri with an original string\n        // that contains the scheme file://.\n        internal static Uri FixFileUri(Uri uri)\n        {\n            if (uri is not null && uri.IsAbsoluteUri &&\n                string.Equals(uri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase) &&\n                string.Compare(uri.OriginalString, 0, Uri.UriSchemeFile, 0, Uri.UriSchemeFile.Length, StringComparison.OrdinalIgnoreCase) != 0)\n            {\n                return new Uri(uri.AbsoluteUri);\n            }\n\n            return uri;\n        }","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Navigation/BaseUriHelper.cs#L353-L389","documentation":"ConvertPackUriToAbsoluteExternallyVisibleUri resolves a pack URI to an externally visible absolute URI for the web browser case; if a relative resource cannot be anchored to a site-of-origin and the pack URI is absolute and points at application resources, it throws InvalidOperationException because application resources cannot be navigated to in a web browser deployment. Pack application resources are internal to the app and have no external URL.","triggerScenarios":"Navigating a Frame/WebBrowser (browser-hosted XBAP/loose XAML scenario) to a pack://application:,,, URI, or passing an absolute pack application URI into ConvertPackUriToAbsoluteExternallyVisibleUri with a relative URI that lacks a site-of-origin base.","commonSituations":"Trying to Navigate() to a resource compiled as Application resource (Build Action=Resource) from browser-hosted content, or pointing a hyperlink/NavigationUri at an application resource in a web deployment.","solutions":["Change the resource's Build Action to 'Content' and Copy to Output Directory so it exists as a file at site-of-origin and can be addressed externally.","Use a siteoforigin pack URI (pack://siteoforigin:,,,/File.xaml) for browser-navigable content.","For full-trust desktop apps, navigate in-process with a NavigationWindow/Frame instead of delegating to the web browser."],"exampleFix":"// before\n// Page.xaml build action: Resource; browser navigation\nwebBrowser.Navigate(new Uri(\"pack://application:,,,/Page.xaml\")); // throws\n// after\n// Set Page.xaml Build Action = Content, Copy to Output = Copy always\nwebBrowser.Navigate(new Uri(\"pack://siteoforigin:,,,/Page.xaml\"));","handlingStrategy":"try-catch","validationCode":"static bool CanNavigateExternally(Uri packUri) => packUri != null && packUri.IsAbsoluteUri && packUri.Scheme == \"pack\" && packUri.Host == \"siteoforigin:,,,\";","typeGuard":null,"tryCatchPattern":"try { browserHost.Navigate(packUri); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"resource\") || ex.Message.Contains(\"navigate\")) { /* fall back to siteoforigin URI or in-app Frame */ }","preventionTips":["In browser-hosted scenarios, use Build Action 'Content' + siteoforigin pack URIs for navigable files.","Keep application resources (pack://application:,,,) for in-process navigation only.","Decide the deployment model early and route navigation accordingly."],"tags":["wpf","pack-uri","navigation","browser-hosted"],"backgroundTag":"unsupported-operation","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"}