dotnet/wpf · error · ArgumentException
SR.InvalidScheme
Error message
SR.InvalidScheme
What it means
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.
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
Example fix
// before
new ByteRangeDownloader(new Uri("pack://application:,,,/asset.xbap"), handle, timeout);
// after
new ByteRangeDownloader(new Uri("https://server/app/asset.xbap"), handle, timeout); Defensive patterns
Strategy: validation
Validate before calling
static bool IsHttpUri(Uri u) => u != null && !u.IsAbsoluteUri == false && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);
Type guard
static bool IsHttpUri(Uri? u) => u?.IsAbsoluteUri == true && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);
Try / catch
try { var d = new ByteRangeDownloader(uri, handle, timeout); } catch (ArgumentException ex) when (ex.ParamName == "requestedUri") { /* fall back or log */ } Prevention
- Only construct ByteRangeDownloader from absolute http/https URIs
- Resolve pack:// URIs to their HTTP source before use
When it happens
Trigger: Calling the public ByteRangeDownloader constructor with a requestedUri whose Scheme is neither 'http' nor 'https' — typically a pack://, file://, or relative/resolved content URI.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- SR.UriNotAbsolute
- SR.UriNotAbsolute
- assembly
- Can only countersign parts with Digital Signature…
- Document PackagePart URI is not valid.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/393627e1bb197c08.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs:404
private void CheckDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(null, SR.ByteRangeDownloaderDisposed);
}
}
/// <summary>
/// Constructor for ByteRangeDownloader
/// </summary>
private ByteRangeDownloader(Uri requestedUri, SafeWaitHandle eventHandle)
{
ArgumentNullException.ThrowIfNull(requestedUri);
// Ensure uri is correct scheme (http or https) Do case-sensitive comparison since Uri.Scheme contract is to return in lower case only.
if (!string.Equals(requestedUri.Scheme, Uri.UriSchemeHttp, StringComparison.Ordinal) && !string.Equals(requestedUri.Scheme, Uri.UriSchemeHttps, StringComparison.Ordinal))
{
throw new ArgumentException(SR.InvalidScheme, nameof(requestedUri));
}
ArgumentNullException.ThrowIfNull(eventHandle);
if (eventHandle.IsInvalid || eventHandle.IsClosed)
{
throw new ArgumentException(SR.InvalidEventHandle, nameof(eventHandle));
}
_requestedUri = requestedUri;
_eventHandle = eventHandle;
}
/// <summary>
/// Check if it has been errored out from the worker thread and re-throw the exception that was
/// thrown from the worker thread
/// </summary>
/// <remarks>No need to lock in this function since the caller always locks before making this call</remarks>View on GitHub (pinned to 81131a70a4)