dotnet/wpf · error · ArgumentException
SR.Format(SR.InvalidByteRanges, "byteRanges")
Error message
SR.Format(SR.InvalidByteRanges, "byteRanges")
What it means
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).
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
Example fix
// before
int[] ranges = {10, 5, 20}; // odd length
ConvertByteRanges(ranges);
// after
int[] ranges = {10, 5, 20, 8};
ConvertByteRanges(ranges); Defensive patterns
Strategy: validation
Validate before calling
bool validPairs = ranges != null && ranges.Length >= 2 && ranges.Length % 2 == 0;
Try / catch
try { ConvertByteRanges(ranges); } catch (ArgumentException ex) { /* log and rebuild pair array */ } Prevention
- 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
When it happens
Trigger: Passing an int[] with length 0 or 1, or an odd length (e.g. {10, 5, 20}) to ConvertByteRanges, which forwards to this check.
Common situations: Building the flat pair array with a stray trailing element, or passing an uninitialized/empty array when there are no ranges to request.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Can only countersign parts with Digital Signature…
- Duplicates not allowed - signature part already exists.
- ExtendedProperty is already part of the…
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/39c256658b3e9db6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs:711
_byteRangesInProgress = null;
}
}
/// <summary>
/// Check if the given byte ranges follows correct format
/// 1) number of items in the array should be even number (It should be one dimensional array consisting pairs
/// of offset and length
/// 2) offset cannot be less than 0
/// 3) length cannot be less than equal to 0
/// </summary>
/// <param name="byteRanges">Byte ranges to be checked</param>
/// <returns>True if the byte ranges are in correct format</returns>
private static void CheckOneDimensionalByteRanges(int[] byteRanges)
{
// The byteRanges should never be less; perf optimization
if (byteRanges.Length < 2 || (byteRanges.Length % 2) != 0)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
}
for (int i = 0; i < byteRanges.Length; i++)
{
if (byteRanges[i] < 0 || byteRanges[i+1] <= 0)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
}
i++;
}
}
/// <summary>
/// Check if the given byte ranges follows correct format
/// 1) array should consist pairs of offset and length
/// 2) offset cannot be less than 0
/// 3) length cannot be less than equal to 0
/// </summary>View on GitHub (pinned to 81131a70a4)