ArgumentOutOfRangeException when loading a file through Stream.Read

I tried to deal with the problem when uploading very large files (> 2 GB) in Silverlight. My application is a boot manager with elevated downloads.

When a file reaches a certain amount of data (2 GB), it throws the following exception:

System.ArgumentOutOfRangeException was caught
  Message=Specified argument was out of the range of valid values.
Parameter name: count
  StackTrace:
   in MS.Internal.InternalNetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
   in MS.Internal.InternalNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   in MySolution.DM.Download.BeginResponseCallback(IAsyncResult ar)
  InnerException: 
Null

The only key I have is this site that shows the implementation BeginCode. This exception occurs only when countit is 0.

My code

/* "Target" is a File object. "source" is a Stream object */

var buffer = new byte[64 * 1024];
int bytesRead;
Target.Seek(0, SeekOrigin.End); // The file might exists when resuming a download

/* The exception throws from inside "source.Read" */
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
{
    Target.Write(buffer, 0, bytesRead);
    _fileBytes = Target.Length;
    Deployment.Current.Dispatcher.BeginInvoke(() => { DownloadPercentual = Double.Parse(Math.Round((decimal)(_fileBytes / (_totalSize / 100)), 5).ToString()); });
}

Target.Close();
logFile.Close();

The error occurs with various types of files, and they come from publicly accessible buckets on Amazon S3. (with regular HTTP requests).

+5
source share
1 answer

, , Silverlight. , 2 , Range.

+1

All Articles