{"record":{"id":"393627e1bb197c08","repo":"dotnet/wpf","slug":"sr-invalidscheme","errorCode":null,"errorMessage":"SR.InvalidScheme","messagePattern":"SR\\.InvalidScheme","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs","lineNumber":404,"sourceCode":"        private void CheckDisposed()\n        {\n            if (_disposed)\n            {\n                throw new ObjectDisposedException(null, SR.ByteRangeDownloaderDisposed);\n            }\n        }\n\n        /// <summary>\n        /// Constructor for ByteRangeDownloader\n        /// </summary>\n        private ByteRangeDownloader(Uri requestedUri, SafeWaitHandle eventHandle)\n        {\n            ArgumentNullException.ThrowIfNull(requestedUri);\n\n            // Ensure uri is correct scheme (http or https) Do case-sensitive comparison since Uri.Scheme contract is to return in lower case only.\n            if (!string.Equals(requestedUri.Scheme, Uri.UriSchemeHttp, StringComparison.Ordinal) && !string.Equals(requestedUri.Scheme, Uri.UriSchemeHttps, StringComparison.Ordinal))\n            {\n                throw new ArgumentException(SR.InvalidScheme, nameof(requestedUri));\n            }\n\n            ArgumentNullException.ThrowIfNull(eventHandle);\n\n            if (eventHandle.IsInvalid || eventHandle.IsClosed)\n            {\n                throw new ArgumentException(SR.InvalidEventHandle, nameof(eventHandle));\n            }\n\n            _requestedUri = requestedUri;\n            _eventHandle = eventHandle;\n        }\n\n        /// <summary>\n        /// Check if it has been errored out from the worker thread and re-throw the exception that was\n        /// thrown from the worker thread\n        /// </summary>\n        /// <remarks>No need to lock in this function since the caller always locks before making this call</remarks>","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs#L386-L422","documentation":"ByteRangeDownloader's constructor only accepts URIs with the http or https scheme, because it downloads bytes from a web server using HTTP range requests. Passing any other scheme (e.g. pack://, file://, ftp://) makes the constructor throw an ArgumentException keyed by SR.InvalidScheme. The comparison is case-sensitive ordinal since Uri.Scheme is contractually lowercase.","triggerScenarios":"Calling the public ByteRangeDownloader constructor with a requestedUri whose Scheme is neither 'http' nor 'https' — typically a pack://, file://, or relative/resolved content URI.","commonSituations":"Developers hand a XAML package URI (pack://...) or a local file path URI to ByteRangeDownloader instead of the absolute remote HTTP URI backing the package.","solutions":["Pass an absolute http:// or https:// URI to the constructor","Resolve the pack:// URI to its underlying HTTP source URL before constructing","If the content is local, use a local stream/file API instead of ByteRangeDownloader"],"exampleFix":"// before\nnew ByteRangeDownloader(new Uri(\"pack://application:,,,/asset.xbap\"), handle, timeout);\n// after\nnew ByteRangeDownloader(new Uri(\"https://server/app/asset.xbap\"), handle, timeout);","handlingStrategy":"validation","validationCode":"static bool IsHttpUri(Uri u) => u != null && !u.IsAbsoluteUri == false && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);","typeGuard":"static bool IsHttpUri(Uri? u) => u?.IsAbsoluteUri == true && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);","tryCatchPattern":"try { var d = new ByteRangeDownloader(uri, handle, timeout); } catch (ArgumentException ex) when (ex.ParamName == \"requestedUri\") { /* fall back or log */ }","preventionTips":["Only construct ByteRangeDownloader from absolute http/https URIs","Resolve pack:// URIs to their HTTP source before use"],"tags":["uri","scheme-validation","wpf","argumentexception"],"backgroundTag":"invalid-url","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"}