0

I am reading bytes from a FileStream. When I try to read 0x8000 bytes from the file (which are there) it says:
"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."

FileStream file = File.OpenRead("test.nes");
byte[] storage = new byte[0xffff];

file.Read(storage, 0x8000, 0x8000);
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0

Do you try to read from the start of the file:

FileStream file = File.OpenRead("test.nes");
byte[] storage = new byte[0xffff];

file.Read(storage, 0x0000, 0x8000);
0

Quick update - turns out I'm just an idiot. I needed to make the destination array size 0x10000 instead of 0xffff

0

You are starting at array index 0x8000 which is the 0x8001 byte into the array (arrays start at 0). You are trying to read one more byte than you have array size (0x8000 + 0x8000 = 0x10000).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.