{"record":{"id":"9d93021385c34fdc","repo":"dotnet/wpf","slug":"sr-nonpackappabsoluteurinotallowed","errorCode":null,"errorMessage":"SR.NonPackAppAbsoluteUriNotAllowed","messagePattern":"SR\\.NonPackAppAbsoluteUriNotAllowed","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":583,"sourceCode":"        ///         \"pack://application:,,,/image/picture1.jpg\"\n        ///\n        ///    Resource from a library assembly\n        ///         \"mylibrary;component/image/picture2.png\" or\n        ///         \"pack://application:,,,/mylibrary;component/image/picture3.jpg\"\n        ///\n        /// </summary>\n        /// <param name=\"uriResource\">the uri maps to the resource</param>\n        /// <returns>PackagePart or null</returns>\n        public static StreamResourceInfo GetResourceStream(Uri uriResource)\n        {\n            ArgumentNullException.ThrowIfNull(uriResource);\n\n            if (uriResource.OriginalString == null)\n                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull, \"uriResource\", \"OriginalString\"));\n\n            if (uriResource.IsAbsoluteUri && !BaseUriHelper.IsPackApplicationUri(uriResource))\n            {\n                throw new ArgumentException(SR.NonPackAppAbsoluteUriNotAllowed);\n            }\n\n            ResourcePart part = GetResourceOrContentPart(uriResource) as ResourcePart;\n            return (part == null) ? null : new StreamResourceInfo(part.GetSeekableStream(), part.ContentType);\n        }\n\n        /// <summary>\n        /// Get PackagePart for a uri, the uri maps to a content file which is associated\n        /// with the application assembly.\n        ///\n        /// If the Uri doesn't map to any content file, this method returns null.\n        ///\n        /// The accepted uri could be relative uri or pack://Application:,,,/ uri.\n        ///\n        ///   Such as\n        ///         \"image/picture1.jpg\"\n        ///    or\n        ///        \"pack://application:,,,/image/picture1.jpg\"","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L565-L601","documentation":"Application.GetResourceStream(Uri) accepts absolute Uris only when they are pack application URIs (BaseUriHelper.IsPackApplicationUri). Any other absolute scheme (http://, file://, etc.) throws ArgumentException with SR.NonPackAppAbsoluteUriNotAllowed. Relative Uris are always accepted and resolved against the app base.","triggerScenarios":"Calling GetResourceStream(new Uri(\"http://example.com/img.png\")) or file:///... ; also absolute pack://siteoforigin URIs (siteOfOrigin is not an application URI).","commonSituations":"Pointing resource loading at remote URLs and expecting GetResourceStream to fetch them; using siteoforigin pack URIs where application URIs are required; config storing full URLs instead of relative resource paths.","solutions":["Pass a relative Uri to the resource: new Uri(\"images/logo.png\", UriKind.Relative)","Use an absolute pack application Uri of the form pack://application:,,,/ResourceFile","Download non-pack content with HttpClient/WebClient instead of GetResourceStream","Guard with uri.IsAbsoluteUri && !BaseUriHelper.IsPackApplicationUri(uri) before calling"],"exampleFix":"// before\nvar sri = Application.GetResourceStream(new Uri(\"http://example.com/logo.png\"));\n\n// after\nvar uri = new Uri(\"images/logo.png\", UriKind.Relative);\nvar sri = Application.GetResourceStream(uri);","handlingStrategy":"validation","validationCode":"if (uri.IsAbsoluteUri && !BaseUriHelper.IsPackApplicationUri(uri))\n    throw new ArgumentException(\"GetResourceStream requires a relative or pack://application Uri\");","typeGuard":"static bool IsPackAppOrRelative(Uri u) => u != null && (!u.IsAbsoluteUri || BaseUriHelper.IsPackApplicationUri(u));","tryCatchPattern":"try { sri = Application.GetResourceStream(uri); }\ncatch (ArgumentException) { sri = Application.GetResourceStream(new Uri(ToRelativeResourcePath(uri), UriKind.Relative)); }","preventionTips":["Store resource paths as relative paths in configuration, never full URLs","Use HttpClient for remote content, GetResourceStream only for embedded resources","Prefer pack://application:,,,/ syntax when absolute Uris are unavoidable"],"tags":["wpf","uri","pack-uri","resources"],"backgroundTag":"invalid-url","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}