Black Locust Software

Technology Solutions for Business

Visual C++ .NET: Error on FileStream->Read

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.

Consider this simple command:
Buffer = new Byte[iBufSize];

When you get the above error, you are writing outside the bounds of your array.

The problem is with the array access, not the FileStream Read.

Remember that iOffset is the offset in the Buffer array, not in the file. To get the offset in the file, you still need to seek to the right place. The FileStream class provides a Seek method for the purpose.

Hope this helps somebody.