{"record":{"id":"ba2b1b675d4d41b6","repo":"dotnet/wpf","slug":"sr-byterangedownloadererroredout","errorCode":null,"errorMessage":"SR.ByteRangeDownloaderErroredOut","messagePattern":"SR\\.ByteRangeDownloaderErroredOut","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs","lineNumber":427,"sourceCode":"            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>\n        private void CheckErroredOutCondition()\n        {\n            if (_erroredOut)\n            {\n                throw new InvalidOperationException(SR.ByteRangeDownloaderErroredOut, _erroredOutException);\n            }\n        }\n\n        /// <summary>\n        /// Download the requested bytes\n        /// </summary>\n        private HttpWebRequest CreateHttpWebRequest(int[,] byteRanges)\n        {\n            HttpWebRequest request;\n\n            // Create the request object\n            request = (HttpWebRequest)WpfWebRequestHelper.CreateRequest(_requestedUri);\n            request.ProtocolVersion = HttpVersion.Version11;\n            request.Method = \"GET\";\n\n            // Set the Proxy to Empty one; If we don't set this to empty one, it will try to find one for us\n            //  and ends up triggering JScript in another assembly. This will throw PolicyException since the JScript\n            //  dll doesn't have execution right. This is a bug in CLR; supposed to be fixed later","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs#L409-L445","documentation":"ByteRangeDownloader enters a terminal error state (_erroredOut) after an asynchronous download failure; once set, all further use is refused with InvalidOperationException(SR.ByteRangeDownloaderErroredOut) wrapping the original exception. The instance can never recover — you must discard it and create a new one.","triggerScenarios":"Calling RequestByteRanges or GetDownloadedByteRanges on a ByteRangeDownloader instance after an internal download/response error already occurred (inner exception via _erroredOutException).","commonSituations":"A network drop or HTTP failure during an earlier async range request poisoned the downloader; callers keep using the stale instance for subsequent ranges.","solutions":["Inspect the InnerException for the root cause (network/HTTP failure)","Create a new ByteRangeDownloader instance and retry the request","Add connectivity/availability checks before retrying"],"exampleFix":"// before\ndownloader.RequestByteRanges(ranges);\n// after\ntry { downloader.RequestByteRanges(ranges); }\ncatch (InvalidOperationException) { downloader = new ByteRangeDownloader(uri, handle, timeout); }","handlingStrategy":"try-catch","validationCode":"// no public API to check _erroredOut; guard by catching","typeGuard":null,"tryCatchPattern":"try { downloader.RequestByteRanges(ranges); } catch (InvalidOperationException ex) { downloader = new ByteRangeDownloader(uri, handle, timeout); /* retry once */ }","preventionTips":["Treat ByteRangeDownloader as single-use after any exception","Create a fresh instance after any download failure","Log InnerException to find the root network/HTTP cause"],"tags":["invalid-operation","wpf","download-error-state"],"backgroundTag":"invalid-state-transition","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"}