{"record":{"id":"699585f40d15a863","repo":"dotnet/wpf","slug":"sr-absoluteurinotallowed","errorCode":null,"errorMessage":"SR.AbsoluteUriNotAllowed","messagePattern":"SR\\.AbsoluteUriNotAllowed","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":355,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Create logic tree from given resource Locator, and associate this\n        /// tree with the given component.\n        /// </summary>\n        /// <param name=\"component\">Root Element</param>\n        /// <param name=\"resourceLocator\">Resource Locator</param>\n        public static void LoadComponent(Object component, Uri resourceLocator)\n        {\n            ArgumentNullException.ThrowIfNull(component);\n            ArgumentNullException.ThrowIfNull(resourceLocator);\n\n            if (resourceLocator.OriginalString == null)\n                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull,\"resourceLocator\", \"OriginalString\"));\n\n            if (resourceLocator.IsAbsoluteUri)\n                throw new ArgumentException(SR.AbsoluteUriNotAllowed);\n\n            // Passed a relative Uri here.\n            // needs to resolve it to Pack://Application.\n            //..\\..\\ in the relative Uri will get stripped when creating the new Uri and resolving to the\n            //PackAppBaseUri, i.e. only relative Uri within the appbase are created here\n            Uri currentUri = new Uri(BaseUriHelper.PackAppBaseUri, resourceLocator);\n\n            //\n            // Generate the ParserContext from packUri\n            //\n            ParserContext pc = new ParserContext\n            {\n                BaseUri = currentUri\n            };\n\n            bool bCloseStream = true;  // Whether or not to close the stream after LoadBaml is done.\n\n            Stream stream = null;  // stream could be extracted from the manifest resource or cached in the","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L337-L373","documentation":"Application.LoadComponent(Object, Uri) only accepts relative Uris, because it resolves them against the application's pack base URI (PackAppBaseUri). An absolute Uri throws ArgumentException with SR.AbsoluteUriNotAllowed. The caller must pass a relative resource path such as \"MyPage.xaml\".","triggerScenarios":"Calling LoadComponent(component, new Uri(\"pack://application:,,,/MyPage.xaml\")) or any other absolute Uri (file://, http://, absolute pack://).","commonSituations":"Storing full pack URIs in configuration and passing them straight to LoadComponent; converting a NavigationWindow's absolute source Uri into a LoadComponent call; mixing up LoadComponent with NavigationService which does accept absolute Uris.","solutions":["Pass a relative Uri: new Uri(\"MyPage.xaml\", UriKind.Relative)","Convert an existing absolute pack Uri to relative with BaseUriHelper or by stripping the pack base: BaseUriHelper.PackAppBaseUri.MakeRelativeUri(absUri)","Use Navigation APIs (frame.Navigate) for absolute Uris instead of LoadComponent"],"exampleFix":"// before\nvar uri = new Uri(\"pack://application:,,,/Views/MyPage.xaml\");\nApplication.LoadComponent(page, uri); // ArgumentException\n\n// after\nvar uri = new Uri(\"Views/MyPage.xaml\", UriKind.Relative);\nApplication.LoadComponent(page, uri);","handlingStrategy":"validation","validationCode":"if (uri.IsAbsoluteUri)\n    uri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(uri);\nApplication.LoadComponent(component, uri);","typeGuard":"static bool IsRelativeLocator(Uri u) => u != null && !u.IsAbsoluteUri;","tryCatchPattern":"try { Application.LoadComponent(component, uri); }\ncatch (ArgumentException) { uri = new Uri(Relativize(uri), UriKind.Relative); Application.LoadComponent(component, uri); }","preventionTips":["Use new Uri(path, UriKind.Relative) for all LoadComponent calls","Convert absolute pack Uris with MakeRelativeUri against PackAppBaseUri","Use Frame.Navigate for scenarios where absolute Uris are expected"],"tags":["wpf","uri","argument-validation","xaml"],"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"}