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);

Recommended Answers

All 3 Replies

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);

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

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.