Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET error when calling System.Net.WebClient.UploadFileAsync
    primarykey
    data
    text
    <p>I am working with the <code>System.Net.WebClient</code> class, and I am attempting to upload a file using the UploadFileAsync method. I am using Visual Studio 2010, and all of my projects are set to use the .NET 4.0 standard runtime, not the client library.</p> <p>Below is a small section of the code that I am using. About 90% of the time I get the following error:</p> <p><strong>Unable to cast object of type 'System.ComponentModel.AsyncOperation' to type 'UploadBitsState'.</strong></p> <pre><code>Stack Trace: at System.Net.WebClient.UploadFileAsyncWriteCallback(Byte[] returnBytes, Exception exception, Object state) at System.Net.WebClient.UploadFileAsync(Uri address, String method, String fileName, Object userToken) at FileUpload._StartUpload() </code></pre> <p>The FTP servers I am attempting to upload to are internal to my organization, but one is running IPSwitches WS-FTP and the other is running an IIS 6.0 FTP site, and I have experienced the same issue with both servers.</p> <p>I have searched high and low for others with a similar problem to no avail.</p> <p>The actual line that the exception occurs on is the <code>_Client.UploadFileAsync</code> method call.</p> <pre><code>private void _StartUpload() { try { _Client = new WebClient { Credentials = _Credentials }; _Client.UploadProgressChanged += ProgressChanged; _Client.UploadFileCompleted += UploadCompleted; _Client.UploadFileAsync(FileBeingUploaded, "STOR", _LocalFile, null); } catch (Exception exception) { // Methods calls removed for brevity } } private void UploadCompleted(Object sender, UploadFileCompletedEventArgs e) { // Methods calls removed for brevity } private void ProgressChanged(object sender, UploadProgressChangedEventArgs e) { // Methods calls removed for brevity } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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