Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange StreamReader.Read() error 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
Here's the part of the code (screenshot, erred during debug run, in IDE):

20200406_StreamReader_ReadingCharBlockErrs_iubdkh.jpg


I cannot comprehend why it errs on the 2nd iteration coz the size of the file it reads is 89 Mb, and I'm reading it by 1 Mb chunks.
Could you, please take a look and tell me who's the crazy one, me or .NET?

TIA!

Regards,

Ilya
 
I'm afraid it is you. You have misunderstood the StreamReader.Read method - the index is the index into the character buffer (i.e. lsBlock) not the position you are reading from in the StreamReader (that particular pointer is maintained internally by the StreamReader as you read ...). So the quick fix is to change

Code:
[COLOR=blue]lnPos = loStreamReader.Read(lsBlock, lnPos + 1, lnChunk)[/color]

to

Code:
[COLOR=blue]lnPos = loStreamReader.Read(lsBlock, 0, lnChunk)[/color]
 
StrongM, you are the savior!
Thank you!

Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top