{"record":{"id":"23cc1799e57fb28e","repo":"dotnet/wpf","slug":"urimustbeabsolute","errorCode":null,"errorMessage":"UriMustBeAbsolute","messagePattern":"UriMustBeAbsolute","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebRequestFactory.cs","lineNumber":55,"sourceCode":"        //\n        //------------------------------------------------------\n        /// <summary>\n        /// Create\n        /// </summary>\n        /// <param name=\"uri\">uri</param>\n        /// <returns>PackWebRequest</returns>\n        /// <remarks>Note that this factory may or may not be \"registered\" with the .NET WebRequest factory as handler\n        /// for \"pack\" scheme web requests.  Because of this, callers should be sure to use the PackUriHelper static class\n        /// to prepare their Uri's.  Calling any PackUriHelper method has the side effect of registering\n        /// the \"pack\" scheme and associating this factory class as its default handler.</remarks>\n        WebRequest IWebRequestCreate.Create(Uri uri)\n        {\n            ArgumentNullException.ThrowIfNull(uri);\n\n            // Ensure uri is absolute - if we don't check now, the get_Scheme property will throw \n            // InvalidOperationException which would be misleading to the caller.\n            if (!uri.IsAbsoluteUri)\n                throw new ArgumentException(SR.UriMustBeAbsolute, nameof(uri));\n\n            // Ensure uri is correct scheme because we can be called directly.  Case sensitive\n            // is fine because Uri.Scheme contract is to return in lower case only.\n            if (!string.Equals(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.Ordinal))\n                throw new ArgumentException(SR.Format(SR.UriSchemeMismatch, PackUriHelper.UriSchemePack), nameof(uri));\n\n#if DEBUG\n            if (_traceSwitch.Enabled)\n                System.Diagnostics.Trace.TraceInformation(\n                        DateTime.Now.ToLongTimeString() + \" \" + DateTime.Now.Millisecond + \" \" +\n                        Environment.CurrentManagedThreadId + \": \" + \n                        \"PackWebRequestFactory - responding to uri: \" + uri);\n#endif\n            // only inspect cache if part name is present because cache only contains an object, not\n            // the stream it was derived from\n            Uri packageUri = System.IO.Packaging.PackUriHelper.GetPackageUri(uri);\n            Uri partUri = System.IO.Packaging.PackUriHelper.GetPartUri(uri);\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebRequestFactory.cs#L37-L73","documentation":"PackWebRequestFactory.Create (IWebRequestFactory.Create) requires an absolute pack:// URI. A relative Uri would throw a misleading InvalidOperationException later when reading Scheme, so Create proactively throws ArgumentException(SR.UriMustBeAbsolute). It also validates the scheme is 'pack' immediately afterwards.","triggerScenarios":"Calling WebRequest.Create / PackWebRequestFactory.Create with a relative Uri instance (uri.IsAbsoluteUri == false).","commonSituations":"Building URIs from config values or user input that omit the pack:// prefix; combining paths with Uri(...) without a base URI.","solutions":["Ensure the Uri is absolute, e.g. new Uri(baseUri, relative) or prepend \"pack://application:,,,/\".","Validate uri.IsAbsoluteUri before calling Create.","Use new Uri(uriString, UriKind.Absolute) so malformed input fails early at construction."],"exampleFix":"// before\nvar req = WebRequest.Create(new Uri(\"/page.xaml\", UriKind.Relative));\n// after\nvar req = WebRequest.Create(new Uri(\"pack://application:,,,/page.xaml\"));","handlingStrategy":"validation","validationCode":"if (uri == null || !uri.IsAbsoluteUri) throw new ArgumentException(\"pack URI must be absolute\", nameof(uri));","typeGuard":"static bool IsAbsolute(Uri u) => u is Uri x && x.IsAbsoluteUri;","tryCatchPattern":"try { return factory.Create(uri); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(uri)) { /* log / fix URI, e.g. resolve against pack://application:,,, base */ throw; }","preventionTips":["Build pack URIs with new Uri(\"pack://application:,,,/\" + path, UriKind.Absolute)","Resolve relative paths against a base pack URI with new Uri(baseUri, relative)","Use UriKind.Absolute so bad input fails at construction"],"tags":["wpf","uri","argument","validation"],"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"}