{"record":{"id":"39c256658b3e9db6","repo":"dotnet/wpf","slug":"sr-format-sr-invalidbyteranges-byteranges","errorCode":null,"errorMessage":"SR.Format(SR.InvalidByteRanges, \"byteRanges\")","messagePattern":"SR\\.Format\\(SR\\.InvalidByteRanges, \"byteRanges\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs","lineNumber":711,"sourceCode":"                _byteRangesInProgress = null;\n            }\n        }\n\n        /// <summary>\n        /// Check if the given byte ranges follows correct format\n        /// 1) number of items in the array should be even number (It should be one dimensional array consisting pairs\n        ///     of offset and length\n        /// 2) offset cannot be less than 0\n        /// 3) length cannot be less than equal to 0\n        /// </summary>\n        /// <param name=\"byteRanges\">Byte ranges to be checked</param>\n        /// <returns>True if the byte ranges are in correct format</returns>\n        private static void CheckOneDimensionalByteRanges(int[] byteRanges)\n        {\n            // The byteRanges should never be less; perf optimization\n            if (byteRanges.Length < 2 || (byteRanges.Length % 2) != 0)\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidByteRanges, \"byteRanges\"));\n            }\n\n            for (int i = 0; i < byteRanges.Length; i++)\n            {\n                if (byteRanges[i] < 0 || byteRanges[i+1] <= 0)\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidByteRanges, \"byteRanges\"));\n                }\n                i++;\n            }\n        }\n\n        /// <summary>\n        /// Check if the given byte ranges follows correct format\n        /// 1) array should consist pairs of offset and length\n        /// 2) offset cannot be less than 0\n        /// 3) length cannot be less than equal to 0\n        /// </summary>","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs#L693-L729","documentation":"CheckOneDimensionalByteRanges enforces that the int[] byteRanges argument is a flat list of (offset, length) pairs — so it must have an even length of at least 2. An empty, odd-length, or single-element array throws ArgumentException(SR.InvalidByteRanges).","triggerScenarios":"Passing an int[] with length 0 or 1, or an odd length (e.g. {10, 5, 20}) to ConvertByteRanges, which forwards to this check.","commonSituations":"Building the flat pair array with a stray trailing element, or passing an uninitialized/empty array when there are no ranges to request.","solutions":["Ensure the array contains complete (offset,length) pairs — even length >= 2","Do not call ConvertByteRanges with an empty array; skip the call when there are no ranges","Verify the loop that builds the array appends values two at a time"],"exampleFix":"// before\nint[] ranges = {10, 5, 20}; // odd length\nConvertByteRanges(ranges);\n// after\nint[] ranges = {10, 5, 20, 8};\nConvertByteRanges(ranges);","handlingStrategy":"validation","validationCode":"bool validPairs = ranges != null && ranges.Length >= 2 && ranges.Length % 2 == 0;","typeGuard":null,"tryCatchPattern":"try { ConvertByteRanges(ranges); } catch (ArgumentException ex) { /* log and rebuild pair array */ }","preventionTips":["Build flat range arrays strictly as (offset,length) pairs","Skip the call entirely when there are no ranges","Add a Debug.Assert(ranges.Length % 2 == 0) at build sites"],"tags":["argument-format","byte-ranges","wpf","argumentexception"],"backgroundTag":"invalid-argument-format","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"}