{"record":{"id":"372d4c50961f174d","repo":"dotnet/wpf","slug":"urischememismatch-pack","errorCode":null,"errorMessage":"UriSchemeMismatch (pack)","messagePattern":"UriSchemeMismatch \\(pack\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebRequestFactory.cs","lineNumber":60,"sourceCode":"        /// <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\n            if (partUri != null)\n            {\n                // Note: we look at PreloadedPackages first before we examine the PackageStore\n                //  This is to make sure that an app cannot override any predefine packages\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebRequestFactory.cs#L42-L78","documentation":"PackWebRequestFactory.Create can be invoked directly (not only through WebRequest.Create scheme dispatch), so it re-checks the URI scheme itself. If uri.Scheme is not exactly \"pack\" (case-sensitive ordinal comparison; Uri.Scheme is always lowercase), it throws ArgumentException with SR.UriSchemeMismatch naming the expected scheme.","triggerScenarios":"Calling PackWebRequestFactory.Create with an absolute Uri whose scheme is not pack (e.g. http://, file://, application:///).","commonSituations":"Passing a generic HTTP URI into a factory that is registered for pack URIs; misconfigured URI templates that drop the pack:// prefix; calling the factory directly instead of via WebRequest.Create.","solutions":["Pass a pack:// scheme URI, e.g. pack://application:,,,/path or pack://siteoforigin:,,,/file.","Check uri.Scheme == PackUriHelper.UriSchemePack before calling the factory.","Use WebRequest.Create(uri) and let scheme dispatch pick the right factory."],"exampleFix":"// before\nvar req = factory.Create(new Uri(\"http://example.com/file.xaml\"));\n// after\nvar req = factory.Create(new Uri(\"pack://http:,,example.com,file.xaml\"));","handlingStrategy":"validation","validationCode":"if (!string.Equals(uri?.Scheme, \"pack\", StringComparison.Ordinal)) throw new ArgumentException(\"expected pack:// scheme\", nameof(uri));","typeGuard":"static bool IsPackUri(Uri u) => u?.IsAbsoluteUri == true && u.Scheme == \"pack\";","tryCatchPattern":"try { return factory.Create(uri); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"pack\")) { uri = new Uri(\"pack://application:,,,\" + uri.PathAndQuery); return factory.Create(uri); }","preventionTips":["Always verify uri.Scheme == \"pack\" before invoking PackWebRequestFactory directly","Prefer WebRequest.Create(uri) so scheme dispatch selects the correct factory","Keep a single helper that constructs pack:// URIs"],"tags":["wpf","uri","scheme","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"}