dotnet/wpf · error · InvalidOperationException
SR.RequestAlreadyStarted
Error message
SR.RequestAlreadyStarted
What it means
The ByteRangeDownloader.Proxy property is immutable once the first HTTP request has been made (_firstRequestMade). Setting Proxy afterwards throws InvalidOperationException(SR.RequestAlreadyStarted) because the download pipeline is already configured and running.
Solutions
- Set Proxy immediately after construction, before any RequestByteRanges call
- Create a new ByteRangeDownloader instance if the proxy must change
- Serialize configuration: gather all settings first, then start downloading
Example fix
// before var d = new ByteRangeDownloader(uri, handle, temp); d.RequestByteRanges(ranges); d.Proxy = newProxy; // throws // after var d = new ByteRangeDownloader(uri, handle, temp); d.Proxy = newProxy; // before first request d.RequestByteRanges(ranges);
Defensive patterns
Strategy: validation
Validate before calling
if (!proxyConfigured && firstRequestAlreadyMade)
throw new InvalidOperationException("Set Proxy before starting downloads");
// configure before first RequestByteRanges call Try / catch
try {
downloader.Proxy = newProxy;
} catch (InvalidOperationException ex) when (ex.Message.Contains("Request")) {
downloader = new ByteRangeDownloader(uri, handle, tempFile) { Proxy = newProxy };
} Prevention
- Configure all downloader properties immediately after construction
- Never reuse a downloader across logically distinct downloads needing different settings
- Centralize downloader setup in one place before download starts
When it happens
Trigger: Assigning downloader.Proxy after a prior RequestByteRanges call has kicked off the first request.
Common situations: Reconfiguring a downloader mid-download, or reusing a cached downloader instance across requests with different proxy settings.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot remove signature from read-only file.
- SchemaInvalidForTransport
- SR.ByteRangeDownloaderDisposed
- SR.Image_EndInitWithoutBeginInit
- SR.Image_OnlyOneInit
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/aa1841604d05cac4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs:302
#region Internal Properties
/// <summary>
/// Proxy for all requests to ByteRangeDownloader
/// </summary>
internal IWebProxy Proxy
{
set
{
CheckDisposed();
ArgumentNullException.ThrowIfNull(value);
if (!_firstRequestMade)
{
_proxy = value;
}
else // Once first request is made it cannot change
{
throw new InvalidOperationException(SR.RequestAlreadyStarted);
}
}
}
/// <summary>
/// Authentication information for all requests to ByteRangeDownloader
/// </summary>
internal ICredentials Credentials
{
set
{
CheckDisposed();
_credentials = value;
}
}
/// <summary>
/// Cache Policy for all requests to ByteRangeDownloaderView on GitHub (pinned to 81131a70a4)