Note that there are some explanatory texts on larger screens.

plurals
  1. POArgumentOutOfRangeException when downloading file via Stream.Read
    text
    copied!<p>I've been struggling with a problem when downloading very big files (>2GB) on Silverlight. My application is an <em>out-of-browser</em> Download Manager running with elevated permissions.</p> <p>When the file reaches a certain ammount of data (2GB), it throws the following exception:</p> <pre><code>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 </code></pre> <p>The only clue I have is <a href="http://reflector.webtropy.com/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/Sockets/NetworkStream@cs/1305376/NetworkStream@cs" rel="nofollow">this site</a>, who shows the <code>BeginCode</code> implementation. This exception only occurs when <code>count</code> is &lt; then 0.</p> <p><strong>My code</strong></p> <pre><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)) &gt; 0) { Target.Write(buffer, 0, bytesRead); _fileBytes = Target.Length; Deployment.Current.Dispatcher.BeginInvoke(() =&gt; { DownloadPercentual = Double.Parse(Math.Round((decimal)(_fileBytes / (_totalSize / 100)), 5).ToString()); }); } Target.Close(); logFile.Close(); </code></pre> <p>The error occurs with different kind of files, and they come from public buckets on Amazon S3. (with regular http requests).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload