Resolving the "System.IO.EndOfStreamException" issue