{"record":{"id":"1dcc8a47a3737551","repo":"dotnet/wpf","slug":"sr-byterangedownloaderdisposed","errorCode":null,"errorMessage":"SR.ByteRangeDownloaderDisposed","messagePattern":"SR\\.ByteRangeDownloaderDisposed","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs","lineNumber":390,"sourceCode":"        //------------------------------------------------------\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        #region Private Methods\n\n        /// <summary>\n        /// Check if the object is disposed\n        /// </summary>\n        /// <remarks>this._disposed is not changed by a thread while another thread is calling this function</remarks>\n        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","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs#L372-L408","documentation":"ObjectDisposedException thrown by ByteRangeDownloader.CheckDisposed when any public operation (GetDownloadedByteRanges, RequestByteRanges, or the Proxy/Credentials/CachePolicy/FileMutex properties) is invoked after the downloader's Dispose path set _disposed to true.","triggerScenarios":"Calling GetDownloadedByteRanges or RequestByteRanges, or reading/writing Proxy, Credentials, CachePolicy, or FileMutex after downloader.Dispose().","commonSituations":"Race conditions where one thread disposes the downloader while another still uses it, or continued use in a finally block / cache after disposal.","solutions":["Stop using the instance after Dispose; create a new ByteRangeDownloader if more downloads are needed","Guard usage with a disposed flag or lock shared between dispose and use","Fix ownership so only one component disposes the downloader"],"exampleFix":"// before\ndownloader.Dispose();\ndownloader.RequestByteRanges(ranges); // throws\n// after\ndownloader.Dispose();\ndownloader = new ByteRangeDownloader(uri, handle, tempFile);\ndownloader.RequestByteRanges(ranges);","handlingStrategy":"try-catch","validationCode":"// guard flag maintained by caller\nbool usable = downloader != null && !disposed;\nif (!usable) throw new InvalidOperationException(\"Downloader already disposed\");","typeGuard":null,"tryCatchPattern":"try {\n    downloader.RequestByteRanges(ranges);\n} catch (ObjectDisposedException) {\n    downloader = new ByteRangeDownloader(uri, handle, tempFile);\n    downloader.RequestByteRanges(ranges);\n}","preventionTips":["Synchronize Dispose and usage with a lock or disposed flag","Dispose only when all outstanding requests are complete","Recreate the downloader instead of reusing a disposed instance"],"tags":["wpf","packaging","object-disposed","lifecycle"],"backgroundTag":"object-disposed","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"}